about summary refs log tree commit diff
path: root/src/libstore
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/gc.cc3
-rw-r--r--src/libstore/local-store.cc30
-rw-r--r--src/libstore/local-store.hh4
-rw-r--r--src/libstore/remote-store.cc4
-rw-r--r--src/libstore/remote-store.hh2
-rw-r--r--src/libstore/store-api.cc8
-rw-r--r--src/libstore/store-api.hh10
7 files changed, 29 insertions, 32 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index d19af1cefaf2..1bc8d162f837 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -608,6 +608,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
 
     state.shouldDelete = options.action == GCOptions::gcDeleteDead || options.action == GCOptions::gcDeleteSpecific;
 
+    if (state.shouldDelete && pathExists(reservedPath))
+        deletePath(reservedPath);
+
     /* Acquire the global GC root.  This prevents
        a) New roots from being added.
        b) Processes from creating new temporary root files. */
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 1a12c91c732d..da4d932df6f9 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -216,8 +216,9 @@ void checkStoreNotSymlink()
 }
 
 
-LocalStore::LocalStore(bool reserveSpace)
-    : didSetSubstituterEnv(false)
+LocalStore::LocalStore()
+    : reservedPath(settings.nixDBPath + "/reserved")
+    , didSetSubstituterEnv(false)
 {
     schemaPath = settings.nixDBPath + "/schema";
 
@@ -276,25 +277,20 @@ LocalStore::LocalStore(bool reserveSpace)
        needed, we reserve some dummy space that we can free just
        before doing a garbage collection. */
     try {
-        Path reservedPath = settings.nixDBPath + "/reserved";
-        if (reserveSpace) {
-            struct stat st;
-            if (stat(reservedPath.c_str(), &st) == -1 ||
-                st.st_size != settings.reservedSize)
-            {
-                AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600);
-                int res = -1;
+        struct stat st;
+        if (stat(reservedPath.c_str(), &st) == -1 ||
+            st.st_size != settings.reservedSize)
+        {
+            AutoCloseFD fd = open(reservedPath.c_str(), O_WRONLY | O_CREAT, 0600);
+            int res = -1;
 #if HAVE_POSIX_FALLOCATE
-                res = posix_fallocate(fd, 0, settings.reservedSize);
+            res = posix_fallocate(fd, 0, settings.reservedSize);
 #endif
-                if (res == -1) {
-                    writeFull(fd, string(settings.reservedSize, 'X'));
-                    ftruncate(fd, settings.reservedSize);
-                }
+            if (res == -1) {
+                writeFull(fd, string(settings.reservedSize, 'X'));
+                ftruncate(fd, settings.reservedSize);
             }
         }
-        else
-            deletePath(reservedPath);
     } catch (SysError & e) { /* don't care about errors */
     }
 
diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh
index a96000d9fbeb..5582acd0f72f 100644
--- a/src/libstore/local-store.hh
+++ b/src/libstore/local-store.hh
@@ -88,11 +88,13 @@ private:
 
     Path linksDir;
 
+    Path reservedPath;
+
 public:
 
     /* Initialise the local store, upgrading the schema if
        necessary. */
-    LocalStore(bool reserveSpace = true);
+    LocalStore();
 
     ~LocalStore();
 
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 2f540c640e0b..a1ac169c2b9e 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -49,7 +49,7 @@ RemoteStore::RemoteStore(size_t maxConnections)
 }
 
 
-ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace)
+ref<RemoteStore::Connection> RemoteStore::openConnection()
 {
     auto conn = make_ref<Connection>();
 
@@ -106,7 +106,7 @@ ref<RemoteStore::Connection> RemoteStore::openConnection(bool reserveSpace)
         }
 
         if (GET_PROTOCOL_MINOR(conn->daemonVersion) >= 11)
-            conn->to << reserveSpace;
+            conn->to << false;
 
         conn->processStderr();
     }
diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh
index af417b84ff9c..ddfb70a669a0 100644
--- a/src/libstore/remote-store.hh
+++ b/src/libstore/remote-store.hh
@@ -106,7 +106,7 @@ private:
 
     ref<Pool<Connection>> connections;
 
-    ref<Connection> openConnection(bool reserveSpace = true);
+    ref<Connection> openConnection();
 
     void setOptions(ref<Connection> conn);
 };
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 9f72bbd83ea3..7058249f06da 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -320,7 +320,7 @@ void Store::exportPaths(const Paths & paths,
 namespace nix {
 
 
-ref<Store> openStoreAt(const std::string & uri, bool reserveSpace)
+ref<Store> openStoreAt(const std::string & uri)
 {
     if (std::string(uri, 0, 7) == "file://") {
         auto store = make_ref<LocalBinaryCacheStore>(std::shared_ptr<Store>(0),
@@ -345,13 +345,13 @@ ref<Store> openStoreAt(const std::string & uri, bool reserveSpace)
 
     return mode == mDaemon
         ? (ref<Store>) make_ref<RemoteStore>()
-        : (ref<Store>) make_ref<LocalStore>(reserveSpace);
+        : (ref<Store>) make_ref<LocalStore>();
 }
 
 
-ref<Store> openStore(bool reserveSpace)
+ref<Store> openStore()
 {
-    return openStoreAt(getEnv("NIX_REMOTE"), reserveSpace);
+    return openStoreAt(getEnv("NIX_REMOTE"));
 }
 
 
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 5fe42c973787..84ede157e87a 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -432,16 +432,12 @@ void removeTempRoots();
 
    If ‘uri’ is empty, it defaults to ‘direct’ or ‘daemon’ depending on
    whether the user has write access to the local Nix store/database.
-
-   The Boolean ‘reserveSpace’ denotes whether some disk space should
-   be reserved to enable future garbage collector runs. It should be
-   set to true *unless* you're going to collect garbage.
-*/
-ref<Store> openStoreAt(const std::string & uri, bool reserveSpace = true);
+   set to true *unless* you're going to collect garbage. */
+ref<Store> openStoreAt(const std::string & uri);
 
 
 /* Open the store indicated by the ‘NIX_REMOTE’ environment variable. */
-ref<Store> openStore(bool reserveSpace = true);
+ref<Store> openStore();
 
 
 /* Display a set of paths in human-readable form (i.e., between quotes