about summary refs log tree commit diff
path: root/src/libstore/local-store.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstore/local-store.cc')
-rw-r--r--src/libstore/local-store.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 5ca776099df0..7afecc1cfc62 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -244,6 +244,18 @@ LocalStore::LocalStore(const Params & params)
 
 LocalStore::~LocalStore()
 {
+    std::shared_future<void> future;
+
+    {
+        auto state(_state.lock());
+        if (state->gcRunning)
+            future = state->gcFuture;
+    }
+
+    if (future.valid()) {
+        printError("waiting for auto-GC to finish on exit...");
+        future.get();
+    }
 
     try {
         auto state(_state.lock());
@@ -991,6 +1003,8 @@ void LocalStore::addToStore(const ValidPathInfo & info, const ref<std::string> &
             StringSource source(*nar);
             restorePath(realPath, source);
 
+            autoGC();
+
             canonicalisePathMetaData(realPath, -1);
 
             optimisePath(realPath); // FIXME: combine with hashPath()
@@ -1025,6 +1039,8 @@ Path LocalStore::addToStoreFromDump(const string & dump, const string & name,
 
             deletePath(realPath);
 
+            autoGC();
+
             if (recursive) {
                 StringSource source(dump);
                 restorePath(realPath, source);
@@ -1097,6 +1113,8 @@ Path LocalStore::addTextToStore(const string & name, const string & s,
 
             deletePath(realPath);
 
+            autoGC();
+
             writeFile(realPath, s);
 
             canonicalisePathMetaData(realPath, -1);