chore: migrate sqlite file location

- avoid using getDatabasePath
- use getApplicationSupportDirectory instead

Signed-off-by: The one with the braid <info@braid.business>
pull/768/head
The one with the braid 1 year ago
parent 461bb8b7a5
commit 949b640c81

@ -75,6 +75,10 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
final path = await getApplicationSupportDirectory();
final sqlFilePath = '$path/${client.clientName}.sqlite';
// migrating from petty unreliable `getDatabasePath`
// See : https://pub.dev/packages/sqflite_common_ffi#limitations
await _migrateLegacyLocation(sqlFilePath, client.clientName);
fileStoragePath = await getTemporaryDirectory();
database = await openDatabase(
sqlFilePath,
@ -91,5 +95,20 @@ Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
);
}
Future<void> _migrateLegacyLocation(
String sqlFilePath,
String clientName,
) async {
final oldPath = await getDatabasesPath();
final oldFilePath = '$oldPath/$clientName.sqlite';
if (oldFilePath == sqlFilePath) return;
final maybeOldFile = File(oldFilePath);
if (await maybeOldFile.exists()) {
await maybeOldFile.copy(sqlFilePath);
await maybeOldFile.delete();
}
}
Future<void> _applySQLCipher(Database db, String cipher) =>
db.rawQuery("PRAGMA KEY='$cipher'");

Loading…
Cancel
Save