chore(backup/creator): Split error log

This commit is contained in:
Ahmad Ansori Palembani 2024-10-02 07:43:31 +07:00
parent 532e1faae4
commit 6d668ae086
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
2 changed files with 6 additions and 9 deletions

View file

@ -9,5 +9,5 @@
## Other ?? Technical stuff, what happened behind the scene
-->
## Fixes
- Fixed more NPE crashes
## Other
- Separate backup error log when destination is null or not a file

View file

@ -18,9 +18,7 @@ import okio.gzip
import okio.sink
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import yokai.domain.backup.BackupPreferences
import yokai.domain.storage.StorageManager
import yokai.i18n.MR
import yokai.util.lang.getString
import java.io.FileOutputStream
@ -37,7 +35,6 @@ class BackupCreator(
val parser = ProtoBuf
private val db: DatabaseHelper = Injekt.get()
private val backupPreferences: BackupPreferences = Injekt.get()
private val storageManager: StorageManager by injectLazy()
@Suppress("RedundantSuspendModifier")
private suspend fun getDatabaseManga(includeReadManga: Boolean) = db.inTransactionReturn {
@ -60,7 +57,7 @@ class BackupCreator(
try {
file = if (isAutoBackup) {
// Get dir of file and create
val dir = storageManager.getAutomaticBackupsDirectory()
val dir = UniFile.fromUri(context, uri)
// Delete older backups
val numberOfBackups = backupPreferences.numberOfBackups().get()
@ -74,10 +71,10 @@ class BackupCreator(
dir?.createFile(Backup.getBackupFilename())
} else {
UniFile.fromUri(context, uri)
}
} ?: throw IllegalStateException("Unable to retrieve backup destination")
if (file == null || !file.isFile) {
throw IllegalStateException("Failed to get handle on file")
if (!file.isFile) {
throw IllegalStateException("Invalid backup destination")
}
val backupManga = mangaBackupCreator(getDatabaseManga(options.readManga), options)