π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Keep log and contacts database opens lock-free
laurenspriemc37686d0ffdb
diff --git a/mobile/packages/contacts/lib/src/db/contacts_database.dart b/mobile/packages/contacts/lib/src/db/contacts_database.dartindex 1b3f1c1906..9a0e9cfbad 100644--- a/mobile/packages/contacts/lib/src/db/contacts_database.dart+++ b/mobile/packages/contacts/lib/src/db/contacts_database.dart@@ -238,6 +238,19 @@ class ContactsDatabase {}Future<void> _migrate(SqliteDatabase database) async {+ final probe = await database.writeLock(+ (tx) => tx.get('PRAGMA user_version'),+ );+ final probedVersion = probe['user_version'] as int;+ if (probedVersion == _databaseVersion) {+ return;+ }+ if (probedVersion > _databaseVersion) {+ throw StateError(+ 'Contacts database version $probedVersion is newer than supported '+ 'version $_databaseVersion',+ );+ }final didMigrate = await database.writeTransaction((tx) async {final result = await tx.get('PRAGMA user_version');final currentVersion = result['user_version'] as int;diff --git a/mobile/packages/log_viewer/lib/src/core/log_database.dart b/mobile/packages/log_viewer/lib/src/core/log_database.dartindex 736455d9da..97f116ea7f 100644--- a/mobile/packages/log_viewer/lib/src/core/log_database.dart+++ b/mobile/packages/log_viewer/lib/src/core/log_database.dart@@ -36,6 +36,21 @@ class LogDatabase {}Future<void> _migrate(SqliteDatabase database) async {+ // Opens must not take the write lock when no migration is pending: a+ // write lock orphaned by a killed engine must never block later opens.+ final probe = await database.writeLock(+ (tx) => tx.get('PRAGMA user_version'),+ );+ final probedVersion = probe['user_version'] as int;+ if (probedVersion == _databaseVersion) {+ return;+ }+ if (probedVersion > _databaseVersion) {+ throw StateError(+ 'Log database version $probedVersion is newer than supported '+ 'version $_databaseVersion',+ );+ }final didMigrate = await database.writeTransaction((tx) async {final result = await tx.get('PRAGMA user_version');final currentVersion = result['user_version'] as int;