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