@@ -23,6 +23,7 @@ import one.mixin.android.extension.getDisplayPath
23
23
import one.mixin.android.extension.getLegacyBackupPath
24
24
import one.mixin.android.extension.getMediaPath
25
25
import one.mixin.android.extension.getOldBackupPath
26
+ import one.mixin.android.util.database.databaseFile
26
27
import one.mixin.android.util.database.dbDir
27
28
import timber.log.Timber
28
29
import java.io.File
@@ -37,7 +38,7 @@ suspend fun backup(
37
38
context : Context ,
38
39
callback : (Result ) -> Unit ,
39
40
) = coroutineScope {
40
- val dbFile = context.getDatabasePath( DB_NAME ) ? : dbDir (context)
41
+ val dbFile = databaseFile (context)
41
42
if (dbFile == null ) {
42
43
withContext(Dispatchers .Main ) {
43
44
Timber .e(" No database files found" )
@@ -194,15 +195,18 @@ suspend fun backupApi29(
194
195
}
195
196
return @withContext
196
197
}
197
- val dbFile = context.getDatabasePath( DB_NAME ) ? : dbDir (context)
198
- if (dbFile == null ) {
198
+ val dbFile = databaseFile (context)
199
+ if (! dbFile.exists() && dbFile.length() <= 0 ) {
199
200
Timber .e(" No database files found" )
200
201
withContext(Dispatchers .Main ) {
201
202
callback(Result .NOT_FOUND )
202
203
}
203
204
return @withContext
204
205
}
205
206
val tmpFile = File (context.getMediaPath(), DB_NAME )
207
+ if (tmpFile.parentFile?.exists() != true ) {
208
+ tmpFile.parentFile?.mkdirs()
209
+ }
206
210
try {
207
211
val inputStream = dbFile.inputStream()
208
212
MixinDatabase .checkPoint()
@@ -260,10 +264,7 @@ suspend fun restore(
260
264
val target =
261
265
internalFindBackup(context, coroutineContext)
262
266
? : return @withContext callback(Result .NOT_FOUND )
263
- var file = context.getDatabasePath(DB_NAME )
264
- if (! file.exists()){
265
- file = dbDir(context)
266
- }
267
+ var file = dbDir(context)
267
268
try {
268
269
if (file.exists()) {
269
270
file.delete()
@@ -313,7 +314,7 @@ suspend fun restoreApi29(
313
314
}
314
315
return @withContext
315
316
}
316
- val file = dbDir (context) ? : return @withContext
317
+ val file = databaseFile (context)
317
318
try {
318
319
val inputStream = context.contentResolver.openInputStream(backupDb.uri)
319
320
if (inputStream == null ) {
@@ -411,7 +412,7 @@ suspend fun findBackupApi29(
411
412
return @withContext null
412
413
}
413
414
val backupChildDirectory = backupDirectory.findFile(BACKUP_DIR_NAME )
414
- val dbFile = backupChildDirectory?.findFile(" mixin.db " )
415
+ val dbFile = backupChildDirectory?.findFile(DB_NAME )
415
416
if (backupChildDirectory == null || ! backupChildDirectory.exists() || backupChildDirectory.length() <= 0 || dbFile == null || ! dbFile.exists() || dbFile.length() <= 0 ) {
416
417
return @withContext null
417
418
}
0 commit comments