diff --git a/mobile/lib/infrastructure/repositories/db.repository.dart b/mobile/lib/infrastructure/repositories/db.repository.dart index 0c7d7c64aa..5d1bdd1cd6 100644 --- a/mobile/lib/infrastructure/repositories/db.repository.dart +++ b/mobile/lib/infrastructure/repositories/db.repository.dart @@ -365,12 +365,11 @@ final class _DriftPoolStreamQueries extends StreamQueryStore { Future deleteSqliteDatabase({required String name}) async { final file = await _databaseFile(name); - for (final path in [file.path, '${file.path}-wal', '${file.path}-shm']) { - final sidecar = File(path); - if (await sidecar.exists()) { - await sidecar.delete(); - } - } + await [ + file.path, + '${file.path}-wal', + '${file.path}-shm', + ].map((path) => File(path).delete().catchError((_) => File(path), test: (e) => e is PathNotFoundException)).wait; } Future openSqliteConnection({required String name}) async { diff --git a/mobile/lib/utils/bootstrap.dart b/mobile/lib/utils/bootstrap.dart index decfe27939..5045b408ed 100644 --- a/mobile/lib/utils/bootstrap.dart +++ b/mobile/lib/utils/bootstrap.dart @@ -74,13 +74,16 @@ Future _openLogDb() async { final logDb = await open(); try { await logDb.customSelect('SELECT COUNT(*) FROM logger_messages').get(); + return logDb; } on SqliteException catch (error) { - if (error.resultCode == 11 || error.resultCode == 26) { - dPrint(() => 'Logs database is unusable, recreating it'); + if (error.resultCode != SqlError.SQLITE_CORRUPT && error.resultCode != SqlError.SQLITE_NOTADB) { await logDb.close(); - await deleteSqliteDatabase(name: 'immich_logs'); - return open(); + rethrow; } + + dPrint(() => 'Logs database is corrupt, recreating it'); + await logDb.close(); + await deleteSqliteDatabase(name: 'immich_logs'); + return open(); } - return logDb; }