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 b1a611b commit 19722d5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class BackupDatabaseService(
private val config: Config
) : CoroutineScope {
val log = LoggerFactory.getLogger("XBackup")!!
val syncExecutor = newFixedThreadPoolContext(1, "XBackup-Sync")

val oneDriveService: IOnedriveUtils by lazy {
ServiceLoader.load(IOnedriveUtils::class.java)
Expand Down Expand Up @@ -243,18 +244,20 @@ class BackupDatabaseService(
error("File hash mismatch when creating backup, file: $path, expected: ${md5}")
}
}
dbQuery {
val backupEntry = BackupEntryTable.insert {
it[this.path] = path.toString()
it[this.size] = sourceFile.length()
it[this.lastModified] = sourceFile.lastModified()
it[this.isDirectory] = sourceFile.isDirectory
it[this.hash] = md5
it[this.zippedSize] = zippedSize
it[this.gzip] = gzip
}.resultedValues!!.single().toBackupEntry()
newEntries.add(backupEntry)
backupEntry
withContext(syncExecutor) {
dbQuery {
val backupEntry = BackupEntryTable.insert {
it[this.path] = path.toString()
it[this.size] = sourceFile.length()
it[this.lastModified] = sourceFile.lastModified()
it[this.isDirectory] = sourceFile.isDirectory
it[this.hash] = md5
it[this.zippedSize] = zippedSize
it[this.gzip] = gzip
}.resultedValues!!.single().toBackupEntry()
newEntries.add(backupEntry)
backupEntry
}
}
} catch (e: IOException) {
throw IOException("Error backing up file: $sourceFile", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Config {
val policies = keepPolicy.map { (k, v) -> k.toMillis() to v.toMillis() }.sortedBy { it.first }
idToTime.toList().sortedBy { (_, time) -> time }.forEach { (id, time) ->
val diff = time - oldest
val policy = policies.firstOrNull { it.first > now - time }
val policy = policies.firstOrNull { it.first > now - time } ?: policies.lastOrNull()
if (policy != null) {
if (diff < policy.second) {
ret.add(id)
Expand Down

0 comments on commit 19722d5

Please sign in to comment.