From 133e7d3e3504e4f229ff40d115a0b347bd4bf205 Mon Sep 17 00:00:00 2001 From: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Tue, 7 Jul 2026 20:20:29 +0530 Subject: [PATCH] review suggestion --- .../infrastructure/repositories/db.repository.dart | 11 +++++------ mobile/lib/utils/bootstrap.dart | 13 ++++++++----- 2 files changed, 13 insertions(+), 11 deletions(-) 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; }