about summary refs log tree commit diff
path: root/src/libstore/store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2006-02-16T13·19+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2006-02-16T13·19+0000
commit651ab439cf5b0c6ab2044257a30b0d94406d57d3 (patch)
treefafb731298c3bdf6f7b81a804864ab9e31e37d67 /src/libstore/store.cc
parentd6f586d0eaa9344a99248cc4dfb7825972f2a174 (diff)
* A simple hack to fix NIX-18: the garbage collector cannot run when
  the disk is full (because to delete something from the Nix store, we
  need a Berkeley DB transaction, which takes up disk space).  Under
  normal operation, we make sure that there exists a file
  /nix/var/nix/db/reserved of 1 MB.  When running the garbage
  collector, we delete that file before we open the Berkeley DB
  environment.

Diffstat (limited to 'src/libstore/store.cc')
-rw-r--r--src/libstore/store.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/libstore/store.cc b/src/libstore/store.cc
index 9c68c3392b4f..25e2d6e36009 100644
--- a/src/libstore/store.cc
+++ b/src/libstore/store.cc
@@ -76,11 +76,25 @@ static void upgradeStore07();
 static void upgradeStore09();
 
 
-void openDB()
+void openDB(bool reserveSpace)
 {
     if (readOnlyMode) return;
 
     try {
+        Path reservedPath = nixDBPath + "/reserved";
+        off_t reservedSize = 1024 * 1024;
+        if (reserveSpace) {
+            struct stat st;
+            if (stat(reservedPath.c_str(), &st) == -1 ||
+                st.st_size != reservedSize)
+                writeFile(reservedPath, string(1024 * 1024, 'X'));
+        }
+        else
+            deletePath(reservedPath);
+    } catch (SysError & e) { /* don't care about errors */
+    }
+
+    try {
         nixDB.open(nixDBPath);
     } catch (DbNoPermission & e) {
         printMsg(lvlTalkative, "cannot access Nix database; continuing anyway");