When wal flag not enabled set db back to default
When a database is set once it will still maintain that
setting even if on the next connection it is not specified.
Any databases that set the wal flag will need to turn the
database back to its default when the flag is disabled or
there will be an error in the access of the database.
Bug: 314419678
Test: atest keystore2_test && atest legacykeystore_test
Change-Id: I008f2d2f6ac055704b721cdd451fc8bdfe448832
diff --git a/keystore2/src/database.rs b/keystore2/src/database.rs
index 93de484..15ceed6 100644
--- a/keystore2/src/database.rs
+++ b/keystore2/src/database.rs
@@ -1014,6 +1014,14 @@
let mut persistent_path_str = "file:".to_owned();
persistent_path_str.push_str(&persistent_path.to_string_lossy());
+ // Connect to database in specific mode
+ let persistent_path_mode = if keystore2_flags::wal_db_journalmode_v3() {
+ "?journal_mode=WAL".to_owned()
+ } else {
+ "?journal_mode=DELETE".to_owned()
+ };
+ persistent_path_str.push_str(&persistent_path_mode);
+
Ok(persistent_path_str)
}
@@ -1036,11 +1044,6 @@
break;
}
- if keystore2_flags::wal_db_journalmode_v2() {
- // Update journal mode to WAL
- conn.pragma_update(None, "journal_mode", "WAL")
- .context("Failed to connect in WAL mode for persistent db")?;
- }
// Drop the cache size from default (2M) to 0.5M
conn.execute("PRAGMA persistent.cache_size = -500;", params![])
.context("Failed to decrease cache size for persistent db")?;