mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2026-01-26 05:24:09 +01:00
Cleanup only created auto backup files (#984)
The automated backup cleanup just deleted every file (recursively in subfolders as well) in the set folder in case it was older than the set backup ttl. This made it impossible to save the automated backups into a folder with different files.
This commit is contained in:
@@ -56,6 +56,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
private var backupSchedulerJobId: String = ""
|
||||
private const val LAST_AUTOMATED_BACKUP_KEY = "lastAutomatedBackup"
|
||||
private val preferences = Injekt.get<Application>().getSharedPreferences("server_util", Context.MODE_PRIVATE)
|
||||
private const val AUTO_BACKUP_FILENAME = "auto"
|
||||
|
||||
init {
|
||||
serverConfig.subscribeTo(
|
||||
@@ -114,7 +115,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
val automatedBackupDir = File(applicationDirs.automatedBackupRoot)
|
||||
automatedBackupDir.mkdirs()
|
||||
|
||||
val backupFile = File(applicationDirs.automatedBackupRoot, Backup.getFilename())
|
||||
val backupFile = File(applicationDirs.automatedBackupRoot, Backup.getFilename(AUTO_BACKUP_FILENAME))
|
||||
|
||||
backupFile.outputStream().use { output -> input.copyTo(output) }
|
||||
}
|
||||
@@ -133,7 +134,7 @@ object ProtoBackupExport : ProtoBackupBase() {
|
||||
return
|
||||
}
|
||||
|
||||
automatedBackupDir.walkTopDown().forEach { file ->
|
||||
automatedBackupDir.listFiles { file -> file.name.startsWith(Backup.getBasename(AUTO_BACKUP_FILENAME)) }?.forEach { file ->
|
||||
try {
|
||||
cleanupAutomatedBackupFile(file)
|
||||
} catch (e: Exception) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package suwayomi.tachidesk.manga.impl.backup.proto.models
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.protobuf.ProtoNumber
|
||||
import xyz.nulldev.androidcompat.util.SafePath
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
|
||||
@@ -19,9 +20,18 @@ data class Backup(
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getFilename(): String {
|
||||
fun getBasename(name: String = ""): String {
|
||||
val namePrefix = "org.suwayomi.tachidesk"
|
||||
val namePrefixSeparator = if (name.isNotEmpty()) "." else ""
|
||||
|
||||
return SafePath.buildValidFilename(namePrefix + namePrefixSeparator + name)
|
||||
}
|
||||
|
||||
fun getFilename(name: String = ""): String {
|
||||
val date = SimpleDateFormat("yyyy-MM-dd_HH-mm").format(Date())
|
||||
return "org.suwayomi.tachidesk_$date.tachibk"
|
||||
val ext = ".tachibk"
|
||||
|
||||
return getBasename(name + "_$date") + ext
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user