Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Nov 17, 2024
1 parent 9cb0488 commit 722c7e7
Show file tree
Hide file tree
Showing 23 changed files with 317 additions and 119 deletions.
3 changes: 3 additions & 0 deletions compat-fake-source/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Fake Sources

This directory contains fake sources that are used to ensure compatibility.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.lucko.luckperms.common.plugin;

import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;

@SuppressWarnings("unused")
public class AbstractLuckPermsPlugin {
@SuppressWarnings("DataFlowIssue")
public final void disable() {
SchedulerAdapter schedulerAdapter = null;
schedulerAdapter.shutdownExecutor();
schedulerAdapter.shutdownScheduler();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* This file is part of LuckPerms, licensed under the MIT License.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package me.lucko.luckperms.common.plugin.scheduler;

public interface SchedulerAdapter {
void shutdownScheduler();
void shutdownExecutor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ interface MultiVersioned {
fun isFileInWorld(world: ServerWorld, p: Path): Boolean

fun broadcast(server: MinecraftServer, text: CrossVersionText)

fun kickAllPlayers(minecraftServer: MinecraftServer, reason: CrossVersionText)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.zly2006.xbackup

import kotlinx.atomicfu.AtomicLong
import kotlinx.atomicfu.atomic
import kotlinx.coroutines.*
import kotlinx.io.IOException
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -31,8 +33,11 @@ class BackupDatabaseService(
}
private val ignoredFiles = setOf(
"x_backup.db",
"x_backup.db-wal",
"x_backup.db-shm",
"x_backup.db-journal",
"session.lock",
"fake_player.gca.json"
)

override val coroutineContext: CoroutineContext
Expand Down Expand Up @@ -82,7 +87,11 @@ class BackupDatabaseService(
val hash: String,
val gzip: Boolean,
val cloudDriveId: Byte?,
)
) {
override fun toString(): String {
return "$id:/$path"
}
}

@Serializable
class Backup(
Expand Down Expand Up @@ -190,8 +199,7 @@ class BackupDatabaseService(
if (MessageDigest.getInstance("MD5").digest(sourceFile.readBytes())
.joinToString("") { "%02x".format(it) } != backupEntry.hash
) {
XBackup.log.error("File hash mismatch when creating backup, file: $path, expected: ${backupEntry.hash}")
error("File hash mismatch")
error("File hash mismatch when creating backup, file: $path, expected: ${backupEntry.hash}")
}
}
newEntries.add(backupEntry)
Expand Down Expand Up @@ -230,7 +238,7 @@ class BackupDatabaseService(
)
}

private suspend fun <T> retry(times: Int, function: suspend () -> T): T {
private suspend inline fun <T> retry(times: Int, function: () -> T): T {
var lastException: Throwable? = null
repeat(times) {
try {
Expand All @@ -241,7 +249,7 @@ class BackupDatabaseService(
delay(1000)
}
}
throw lastException!!
throw RuntimeException("Retry failed", lastException)
}

suspend fun deleteBackup(id: Int) {
Expand Down Expand Up @@ -296,7 +304,8 @@ class BackupDatabaseService(
it.deleteRecursively()
}
}
map.map {
val done = atomic(0)
val deferredList = map.map {
this@BackupDatabaseService.async {
val path = target.resolve(it.key).normalize().createParentDirectories()
if (it.value.lastModified == path.toFile().lastModified() && it.value.size == path.fileSize()) {
Expand Down Expand Up @@ -350,14 +359,25 @@ class BackupDatabaseService(
}
require(path.fileSize() == it.value.size)
path.toFile().setLastModified(it.value.lastModified)
XBackup.log.info("Restored file ${it.key}")
val done = done.incrementAndGet()
if (done % 30 == 0) {
XBackup.log.info("[X Backup] Restored $done files // current: ${it.key}")
}
}
}
} catch (e: Exception) {
XBackup.log.error("", e)
}
}
}.awaitAll()
}
val reportJob = this@BackupDatabaseService.launch {
while (done.value < map.size) {
delay(5000)
XBackup.log.info("[X Backup] Restored ${done.value}/${map.size} files")
}
}
deferredList.awaitAll()
reportJob.cancelAndJoin()
XBackup.log.info("Restored backup $id")
}
}
Expand Down
Loading

0 comments on commit 722c7e7

Please sign in to comment.