Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Dec 2, 2024
1 parent 19722d5 commit f8bc08b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ import kotlin.io.path.*
class BackupDatabaseService(
val database: Database,
private val blobDir: Path,
private val config: Config
config: Config
) : CoroutineScope {
val log = LoggerFactory.getLogger("XBackup")!!
val syncExecutor = newFixedThreadPoolContext(1, "XBackup-Sync")
private val log = LoggerFactory.getLogger("XBackup")!!
private val syncExecutor = newFixedThreadPoolContext(1, "XBackup-Sync")
init {
require(blobDir.isAbsolute) {
"Blob directory must be absolute"
}
if (!blobDir.isDirectory()) {
log.warn("Blob directory not found, creating...")
}
}

val oneDriveService: IOnedriveUtils by lazy {
ServiceLoader.load(IOnedriveUtils::class.java)
Expand Down
19 changes: 18 additions & 1 deletion src/main/kotlin/com/github/zly2006/xbackup/XBackup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.decodeFromStream
import kotlinx.serialization.json.put
import net.fabricmc.api.ModInitializer
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
Expand Down Expand Up @@ -146,7 +147,23 @@ object XBackup : ModInitializer {
url = "jdbc:sqlite:$worldPath/x_backup.db"
}
)
service = BackupDatabaseService(database, Path(".").absolute().resolve(config.blobPath).normalize(), config)
if (config.mirrorMode) {
val sourceConfig = kotlin.runCatching {
Json.decodeFromStream<Config>(Path(config.mirrorFrom!!, "config", "x-backup.config.json").inputStream())
}.getOrNull()
if (sourceConfig == null) {
log.error("Failed to load config from source server!")
}
val config = sourceConfig ?: config
service = BackupDatabaseService(
database,
Path(config.mirrorFrom!!).resolve(config.blobPath).absolute().normalize(),
config
)
}
else {
service = BackupDatabaseService(database, Path(".").absolute().resolve(config.blobPath).normalize(), config)
}
if (!config.mirrorMode) {
startCrontabJob(server)
}
Expand Down

0 comments on commit f8bc08b

Please sign in to comment.