diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/gc.cc | 3 | ||||
-rw-r--r-- | src/libstore/local-store.cc | 30 | ||||
-rw-r--r-- | src/libstore/local-store.hh | 4 | ||||
-rw-r--r-- | src/libstore/remote-store.cc | 4 | ||||
-rw-r--r-- | src/libstore/remote-store.hh | 2 | ||||
-rw-r--r-- | src/libstore/store-api.cc | 8 | ||||
-rw-r--r-- | src/libstore/store-api.hh | 10 | ||||
-rw-r--r-- | src/nix-collect-garbage/nix-collect-garbage.cc | 2 | ||||
-rw-r--r-- | src/nix-daemon/nix-daemon.cc | 5 | ||||
-rw-r--r-- | src/nix-store/nix-store.cc | 2 |
10 files changed, 33 insertions, 37 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 diff --git a/src/nix-collect-garbage/nix-collect-garbage.cc b/src/nix-collect-garbage/nix-collect-garbage.cc index b9ccafb751c1..3aa348581b19 100644 --- a/src/nix-collect-garbage/nix-collect-garbage.cc +++ b/src/nix-collect-garbage/nix-collect-garbage.cc @@ -82,7 +82,7 @@ int main(int argc, char * * argv) // Run the actual garbage collector. if (!dryRun) { - auto store = openStore(false); + auto store = openStore(); options.action = GCOptions::gcDeleteDead; GCResults results; PrintFreed freed(true, results); diff --git a/src/nix-daemon/nix-daemon.cc b/src/nix-daemon/nix-daemon.cc index 27694eac1a8c..e3c12ea0e0ea 100644 --- a/src/nix-daemon/nix-daemon.cc +++ b/src/nix-daemon/nix-daemon.cc @@ -562,9 +562,8 @@ static void processConnection(bool trusted) if (GET_PROTOCOL_MINOR(clientVersion) >= 14 && readInt(from)) setAffinityTo(readInt(from)); - bool reserveSpace = true; if (GET_PROTOCOL_MINOR(clientVersion) >= 11) - reserveSpace = readInt(from) != 0; + readInt(from); // obsolete reserveSpace /* Send startup error messages to the client. */ startWork(); @@ -582,7 +581,7 @@ static void processConnection(bool trusted) #endif /* Open the store. */ - auto store = make_ref<LocalStore>(reserveSpace); + auto store = make_ref<LocalStore>(); stopWork(); to.flush(); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 7ec61eb625b0..48c2865e5ecc 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -1131,7 +1131,7 @@ int main(int argc, char * * argv) if (!op) throw UsageError("no operation specified"); if (op != opDump && op != opRestore) /* !!! hack */ - store = openStore(op != opGC); + store = openStore(); op(opFlags, opArgs); }); |