about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2008-07-18T15·34+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2008-07-18T15·34+0000
commit989176c56e1996a7df87bb501ad09aed1f3b395d (patch)
tree998fc55a3e5a918840a835a17e690ea601276f6b /src/libstore
parent8bc591a6f07ee577b5aa594dfa705f3ddabd269d (diff)
* Allow read-only access to the store (e.g., non-root users on NixOS
  can do operations like "nix-store -qR <path>" even without the Nix
  daemon).

Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/local-store.cc14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 105f711228a8..d886ba558606 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <utime.h>
 #include <fcntl.h>
+#include <errno.h>
 
 
 namespace nix {
@@ -48,8 +49,14 @@ LocalStore::LocalStore()
 
     checkStoreNotSymlink();
 
-    Path globalLockPath = nixDBPath + "/big-lock";
-    globalLock = openLockFile(globalLockPath.c_str(), true);
+    try {
+        Path globalLockPath = nixDBPath + "/big-lock";
+        globalLock = openLockFile(globalLockPath.c_str(), true);
+    } catch (SysError & e) {
+        if (e.errNo != EACCES) throw;
+        readOnlyMode = true;
+        return;
+    }
     
     if (!lockFile(globalLock, ltRead, false)) {
         printMsg(lvlError, "waiting for the big Nix store lock...");
@@ -59,9 +66,6 @@ LocalStore::LocalStore()
     createDirs(nixDBPath + "/info");
     createDirs(nixDBPath + "/referrer");
 
-    //printMsg(lvlTalkative, "cannot access Nix database; continuing anyway");
-    //readOnlyMode = true;
-
     int curSchema = getSchema();
     if (curSchema > nixSchemaVersion)
         throw Error(format("current Nix store schema is version %1%, but I only support %2%")