Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Refactor vault persist to separate method (#1325)

Leendert de Borsted8642de4165
diff --git a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt
index e167af32d..81f647cbd 100644
--- a/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt
+++ b/apps/mobile-app/android/app/src/main/java/net/aliasvault/app/vaultstore/VaultDatabase.kt
@@ -154,12 +154,10 @@ class VaultDatabase(
}
/**
- * Commit a SQL transaction and persist the encrypted vault.
+ * Persist the in-memory database to encrypted local storage.
+ * This method can be called independently to persist the database without committing a transaction.
*/
- fun commitTransaction() {
- dbConnection?.setTransactionSuccessful()
- dbConnection?.endTransaction()
-
+ fun persistDatabaseToEncryptedStorage() {
val tempDbFile = File.createTempFile("temp_db", ".sqlite")
tempDbFile.deleteOnExit()
@@ -207,6 +205,15 @@ class VaultDatabase(
}
}
+ /**
+ * Commit a SQL transaction and persist the encrypted vault.
+ */
+ fun commitTransaction() {
+ dbConnection?.setTransactionSuccessful()
+ dbConnection?.endTransaction()
+ persistDatabaseToEncryptedStorage()
+ }
+
/**
* Rollback a SQL transaction on the vault.
*/
diff --git a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
index 8f67ced6a..a396e7b9a 100644
--- a/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
+++ b/apps/mobile-app/ios/VaultStoreKit/VaultStore+Query.swift
@@ -107,15 +107,13 @@ extension VaultStore {
try dbConnection.execute("BEGIN TRANSACTION")
}
- /// Commit a transaction on the database. This is required for all database operations that modify the database.
- /// Committing a transaction will also trigger a persist from the in-memory database to the encrypted database file.
- public func commitTransaction() throws {
+ /// Persist the in-memory database to encrypted local storage.
+ /// This method can be called independently to persist the database without committing a transaction.
+ public func persistDatabaseToEncryptedStorage() throws {
guard let dbConnection = self.dbConnection else {
throw NSError(domain: "VaultStore", code: 4, userInfo: [NSLocalizedDescriptionKey: "Database not initialized"])
}
- try dbConnection.execute("COMMIT")
-
let tempDbPath = FileManager.default.temporaryDirectory.appendingPathComponent("temp_db.sqlite")
try Data().write(to: tempDbPath)
@@ -171,6 +169,17 @@ extension VaultStore {
try? FileManager.default.removeItem(at: tempDbPath)
}
+ /// Commit a transaction on the database. This is required for all database operations that modify the database.
+ /// Committing a transaction will also trigger a persist from the in-memory database to the encrypted database file.
+ public func commitTransaction() throws {
+ guard let dbConnection = self.dbConnection else {
+ throw NSError(domain: "VaultStore", code: 4, userInfo: [NSLocalizedDescriptionKey: "Database not initialized"])
+ }
+
+ try dbConnection.execute("COMMIT")
+ try persistDatabaseToEncryptedStorage()
+ }
+
/// Rollback a transaction on the database on error.
public func rollbackTransaction() throws {
guard let dbConnection = self.dbConnection else {