summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-11-19 17:07:29 +0100
committerLudovic Courtès <ludo@gnu.org>2015-05-11 17:40:44 +0200
commitf160a30d5612506de41a8206a57eccee1cd85fb7 (patch)
treeb20acdd3b85ffc01619ef5a9b20deef47332085c
parenta64744477d95e6932ae0fefc7cc358b56b8c397f (diff)
downloadguix-f160a30d5612506de41a8206a57eccee1cd85fb7.tar.gz
Clean up temp roots in a more C++ way
-rw-r--r--nix/libstore/gc.cc26
-rw-r--r--nix/libstore/local-store.cc9
-rw-r--r--nix/libstore/local-store.hh4
3 files changed, 13 insertions, 26 deletions
diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index 2a53b54110..e019d9343e 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -145,11 +145,6 @@ Path addPermRoot(StoreAPI & store, const Path & _storePath,
 }
 
 
-/* The file to which we write our temporary roots. */
-static Path fnTempRoots;
-static AutoCloseFD fdTempRoots;
-
-
 void LocalStore::addTempRoot(const Path & path)
 {
     /* Create the temporary roots file for this process. */
@@ -204,27 +199,6 @@ void LocalStore::addTempRoot(const Path & path)
 }
 
 
-void removeTempRoots()
-{
-    if (fdTempRoots != -1) {
-        fdTempRoots.close();
-        unlink(fnTempRoots.c_str());
-    }
-}
-
-
-/* Automatically clean up the temporary roots file when we exit. */
-struct RemoveTempRoots
-{
-    ~RemoveTempRoots()
-    {
-        removeTempRoots();
-    }
-};
-
-static RemoveTempRoots autoRemoveTempRoots __attribute__((unused));
-
-
 typedef std::shared_ptr<AutoCloseFD> FDPtr;
 typedef list<FDPtr> FDs;
 
diff --git a/nix/libstore/local-store.cc b/nix/libstore/local-store.cc
index 2f5c0e178f..e3de33b6e4 100644
--- a/nix/libstore/local-store.cc
+++ b/nix/libstore/local-store.cc
@@ -363,6 +363,15 @@ LocalStore::~LocalStore()
     } catch (...) {
         ignoreException();
     }
+
+    try {
+        if (fdTempRoots != -1) {
+            fdTempRoots.close();
+            unlink(fnTempRoots.c_str());
+        }
+    } catch (...) {
+        ignoreException();
+    }
 }
 
 
diff --git a/nix/libstore/local-store.hh b/nix/libstore/local-store.hh
index dccdba533a..e0aabdba42 100644
--- a/nix/libstore/local-store.hh
+++ b/nix/libstore/local-store.hh
@@ -244,6 +244,10 @@ private:
 
     bool didSetSubstituterEnv;
 
+    /* The file to which we write our temporary roots. */
+    Path fnTempRoots;
+    AutoCloseFD fdTempRoots;
+
     int getSchema();
 
     void openDB(bool create);