From 1256ab3b446d8e35225c36e71abb50ee964ea050 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 19 Nov 2014 17:07:29 +0100 Subject: [PATCH] Clean up temp roots in a more C++ way --- src/libstore/gc.cc | 26 -------------------------- src/libstore/local-store.cc | 9 +++++++++ src/libstore/local-store.hh | 4 ++++ 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index ebee4859f..0806430ef 100644 --- a/src/libstore/gc.cc +++ b/src/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 FDPtr; typedef list FDs; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f08c877fe..fc48c0405 100644 --- a/src/libstore/local-store.cc +++ b/src/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/src/libstore/local-store.hh b/src/libstore/local-store.hh index dccdba533..e0aabdba4 100644 --- a/src/libstore/local-store.hh +++ b/src/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);