about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-31T21·20+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-31T21·20+0000
commit207bdcbe86bac5fb9e650d26b22ae33c667151e4 (patch)
tree9ef6560b23571b869214cb3cd2381c1d66f620b7
parent252c9c91abe146e9c6b16d795c6566df4adafe56 (diff)
* Automatically remove temporary root files.
-rw-r--r--src/libmain/shared.cc14
-rw-r--r--src/libstore/gc.cc12
-rw-r--r--src/libstore/gc.hh5
3 files changed, 30 insertions, 1 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 395d9c8b4cd6..23fcf28916be 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -13,6 +13,7 @@ extern "C" {
 }
 
 #include "globals.hh"
+#include "gc.hh"
 #include "shared.hh"
 
 #include "config.h"
@@ -55,6 +56,15 @@ void checkStoreNotSymlink(Path path)
 }
 
 
+struct RemoveTempRoots 
+{
+    ~RemoveTempRoots()
+    {
+        removeTempRoots();
+    }
+};
+
+
 void initDerivationsHelpers();
 
 
@@ -171,6 +181,10 @@ static void initAndRun(int argc, char * * argv)
         else remaining.push_back(arg);
     }
 
+    /* Automatically clean up the temporary roots file when we
+       exit. */
+    RemoveTempRoots removeTempRoots;
+
     run(remaining);
 }
 
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 222a1ff95cc2..af40e0b9286a 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -63,6 +63,15 @@ void addTempRoot(const Path & path)
 }
 
 
+void removeTempRoots()
+{
+    if (fdTempRoots != -1) {
+        fdTempRoots.close();
+        unlink(fnTempRoots.c_str());
+    }
+}
+
+
 typedef shared_ptr<AutoCloseFD> FDPtr;
 typedef list<FDPtr> FDs;
 
@@ -94,7 +103,8 @@ static void readTempRoots(PathSet & tempRoots, FDs & fds)
         if (lockFile(*fd, ltWrite, false)) {
             printMsg(lvlError, format("removing stale temporary roots file `%1%'")
                 % path);
-            /* !!! write token, unlink */
+            unlink(path.c_str());
+            writeFull(*fd, (const unsigned char *) "d", 1);
             continue;
         }
 
diff --git a/src/libstore/gc.hh b/src/libstore/gc.hh
index c8f908b152aa..91c5be91406b 100644
--- a/src/libstore/gc.hh
+++ b/src/libstore/gc.hh
@@ -21,5 +21,10 @@ void collectGarbage(const PathSet & roots, GCAction action,
    deadlock. */
 void addTempRoot(const Path & path);
 
+/* Remove the temporary roots file for this process.  Any temporary
+   root becomes garbage after this point unless it has been registered
+   as a (permanent) root. */
+void removeTempRoots();
+
 
 #endif /* !__GC_H */