mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
fix(backup/creator): Backup should be created after backup file path is validated
This commit is contained in:
parent
24784d6e78
commit
ad3bb53519
1 changed files with 20 additions and 20 deletions
|
@ -38,33 +38,23 @@ class BackupCreator(
|
|||
private val preferences: PreferencesHelper = Injekt.get()
|
||||
private val storageManager: StorageManager by injectLazy()
|
||||
|
||||
@Suppress("RedundantSuspendModifier")
|
||||
private suspend fun getDatabaseManga(includeReadManga: Boolean) = db.inTransactionReturn {
|
||||
db.getFavoriteMangas().executeAsBlocking() +
|
||||
if (includeReadManga) {
|
||||
db.getReadNotInLibraryMangas().executeAsBlocking()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create backup Json file from database
|
||||
*
|
||||
* @param uri path of Uri
|
||||
* @param isAutoBackup backup called from scheduled backup job
|
||||
*/
|
||||
@Suppress("RedundantSuspendModifier")
|
||||
suspend fun createBackup(uri: Uri, options: BackupOptions, isAutoBackup: Boolean): String {
|
||||
val databaseManga = db.inTransactionReturn {
|
||||
db.getFavoriteMangas().executeAsBlocking() +
|
||||
if (options.readManga) {
|
||||
db.getReadNotInLibraryMangas().executeAsBlocking()
|
||||
} else {
|
||||
emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
val backupManga = mangaBackupCreator(databaseManga, options)
|
||||
val backup = Backup(
|
||||
backupManga = backupManga,
|
||||
backupCategories = categoriesBackupCreator(options),
|
||||
backupBrokenSources = emptyList(),
|
||||
backupSources = sourcesBackupCreator(backupManga),
|
||||
backupPreferences = preferenceBackupCreator.backupAppPreferences(options),
|
||||
backupSourcePreferences = preferenceBackupCreator.backupSourcePreferences(options),
|
||||
)
|
||||
|
||||
var file: UniFile? = null
|
||||
try {
|
||||
file = if (isAutoBackup) {
|
||||
|
@ -89,6 +79,16 @@ class BackupCreator(
|
|||
throw IllegalStateException("Failed to get handle on file")
|
||||
}
|
||||
|
||||
val backupManga = mangaBackupCreator(getDatabaseManga(options.readManga), options)
|
||||
val backup = Backup(
|
||||
backupManga = backupManga,
|
||||
backupCategories = categoriesBackupCreator(options),
|
||||
backupBrokenSources = emptyList(),
|
||||
backupSources = sourcesBackupCreator(backupManga),
|
||||
backupPreferences = preferenceBackupCreator.backupAppPreferences(options),
|
||||
backupSourcePreferences = preferenceBackupCreator.backupSourcePreferences(options),
|
||||
)
|
||||
|
||||
val byteArray = parser.encodeToByteArray(Backup.serializer(), backup)
|
||||
if (byteArray.isEmpty()) {
|
||||
throw IllegalStateException(context.getString(MR.strings.empty_backup_error))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue