about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-09-01T11·36+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-09-01T11·36+0000
commite4907411c2d902215d1a18456ce8b0c653650461 (patch)
tree2af8a0db993b9ce847f790de8091093e01f23855 /src/libstore
parentbf0dde959771661c6893001a7e0779b65d7be490 (diff)
* Only do "pragma journal_mode = ..." if the current journal mode
  differs from the desired mode.  There is an open SQLite ticket
  `Executing "PRAGMA journal_mode" may delete journal file while it is
  in use.'

Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index fd6ad6464f3b..c0c1461b4974 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -303,7 +303,16 @@ void LocalStore::openDB(bool create)
        The downside is that it doesn't work over NFS, so allow
        truncate mode alternatively. */
     string mode = queryBoolSetting("use-sqlite-wal", true) ? "wal" : "truncate";
-    if (sqlite3_exec(db, ("pragma main.journal_mode = " + mode + ";").c_str(), 0, 0, 0) != SQLITE_OK)
+    string prevMode;
+    {
+        SQLiteStmt stmt;
+        stmt.create(db, "pragma main.journal_mode;");
+        if (sqlite3_step(stmt) != SQLITE_ROW)
+            throw SQLiteError(db, "querying journal mode");
+        prevMode = string((const char *) sqlite3_column_text(stmt, 0));
+    }
+    if (prevMode != mode &&
+        sqlite3_exec(db, ("pragma main.journal_mode = " + mode + ";").c_str(), 0, 0, 0) != SQLITE_OK)
         throw SQLiteError(db, "setting journal mode");
 
     /* Increase the auto-checkpoint interval to 8192 pages.  This