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.
This commit is contained in:
Eelco Dolstra 2014-02-01 16:57:38 +01:00
parent 2f9bb5c7e7
commit d6582c04c1

View file

@ -354,10 +354,14 @@ int LocalStore::getSchema()
void LocalStore::openDB(bool create) 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. */ /* 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) 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) if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
throwSQLiteError(db, "setting timeout"); throwSQLiteError(db, "setting timeout");