about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-01T15·57+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-02-01T15·57+0100
commitd6582c04c169d7ac32820d855de92ca4e4969de3 (patch)
tree12a5e6283a866d7d23350f7db1ec077d282b3bd8 /src/libstore
parent2f9bb5c7e744ddca3fbe5576e520a3e80c106c55 (diff)
Give a friendly error message if the DB directory is not writable
Previously we would say "error: setting synchronous mode: unable to
open database file" which isn't very helpful.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 3c367c080815..4ac7d7f4e6f7 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -354,10 +354,14 @@ int LocalStore::getSchema()
 
 void LocalStore::openDB(bool create)
 {
+    if (access(settings.nixDBPath.c_str(), R_OK | W_OK))
+        throw SysError(format("Nix database directory `%1%' is not writable") % settings.nixDBPath);
+
     /* Open the Nix database. */
-    if (sqlite3_open_v2((settings.nixDBPath + "/db.sqlite").c_str(), &db.db,
+    string dbPath = settings.nixDBPath + "/db.sqlite";
+    if (sqlite3_open_v2(dbPath.c_str(), &db.db,
             SQLITE_OPEN_READWRITE | (create ? SQLITE_OPEN_CREATE : 0), 0) != SQLITE_OK)
-        throw Error("cannot open SQLite database");
+        throw Error(format("cannot open Nix database `%1%'") % dbPath);
 
     if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
         throwSQLiteError(db, "setting timeout");