Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ class BackupDatabaseService(
1 -> withContext(Dispatchers.IO) {
GZIPInputStream(blob.inputStream())
}
2 -> ZipInputStream(blob.inputStream()).use {
2 -> ZipInputStream(blob.inputStream()).also {
@Suppress("ControlFlowWithEmptyBody")
while (it.nextEntry.let { zipEntry ->
if (zipEntry == null) false
else zipEntry.name != path
}) {
}
it
}

else -> error("Unknown compress type: $compress")
Expand Down Expand Up @@ -602,8 +601,7 @@ class BackupDatabaseService(
val input = requireNotNull(it.getInputStreamInternal(this)) {
"Blob not found for file ${it.path}, hash: ${it.hash}"
}
input.copyTo(zip)
input.close()
input.use { s -> s.copyTo(zip) }
}
}
val md5 = MessageDigest.getInstance("MD5").digest(stream.toByteArray())
Expand Down Expand Up @@ -656,8 +654,7 @@ class BackupDatabaseService(
val input = requireNotNull(it.getInputStream(this)) {
"Blob not found for file ${it.path}, hash: ${it.hash}"
}
input.copyTo(outputStream)
input.close()
input.use { s -> s.copyTo(outputStream) }
}
done++
activeTaskProgress = 100 * done / backup.entries.size
Expand Down
12 changes: 10 additions & 2 deletions src/main/kotlin/com/github/zly2006/xbackup/XBackup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,16 @@ object XBackup : ModInitializer {
val localBackup = File("x_backup.db.back")
localBackup.delete()
try {
(service.database.connector().connection as? SQLiteConnection)?.createStatement()
?.execute("VACUUM INTO '$localBackup';")
val exposedConn = service.database.connector()
try {
(exposedConn.connection as? SQLiteConnection)?.let { conn ->
conn.createStatement().use { stmt ->
stmt.execute("VACUUM INTO '$localBackup';")
}
}
} finally {
exposedConn.close()
}
} catch (e: Exception) {
log.error("Error backing up database", e)
}
Expand Down
Loading