From dbe553c3846061f022dae906276b77a8430cce6a Mon Sep 17 00:00:00 2001 From: Jaroslav Rohel Date: Thu, 18 Oct 2018 16:06:55 +0200 Subject: [PATCH] [swdb] create persistent WAL files (RhBug:1640235) --- libdnf/utils/sqlite3/Sqlite3.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libdnf/utils/sqlite3/Sqlite3.cpp b/libdnf/utils/sqlite3/Sqlite3.cpp index 021b5d2..27fed56 100644 --- a/libdnf/utils/sqlite3/Sqlite3.cpp +++ b/libdnf/utils/sqlite3/Sqlite3.cpp @@ -30,9 +30,17 @@ SQLite3::open() sqlite3_close(db); throw LibException(result, "Open failed"); } - // sqlite doesn't behave correctly in chroots without following line: - // turn foreign key checking on - exec("PRAGMA locking_mode = NORMAL; PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;"); +#if SQLITE_VERSION_NUMBER >= 3022000 + int enabled = 1; + sqlite3_file_control(db, "main", SQLITE_FCNTL_PERSIST_WAL, &enabled); + if (sqlite3_db_readonly(db, "main") == 1) + exec("PRAGMA locking_mode = NORMAL; PRAGMA foreign_keys = ON;"); + else + exec("PRAGMA locking_mode = NORMAL; PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;"); +#else + // Journal mode WAL in readonly mode is supported from sqlite version 3.22.0 + exec("PRAGMA locking_mode = NORMAL; PRAGMA journal_mode = TRUNCATE; PRAGMA foreign_keys = ON;"); +#endif sqlite3_busy_timeout(db, 10000); } } -- libgit2 0.26.7