Clean up temp roots in a more C++ way

This commit is contained in:
Eelco Dolstra 2014-11-19 17:07:29 +01:00
parent ed306febb5
commit 1256ab3b44
3 changed files with 13 additions and 26 deletions

View file

@ -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) void LocalStore::addTempRoot(const Path & path)
{ {
/* Create the temporary roots file for this process. */ /* 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 std::shared_ptr<AutoCloseFD> FDPtr;
typedef list<FDPtr> FDs; typedef list<FDPtr> FDs;

View file

@ -363,6 +363,15 @@ LocalStore::~LocalStore()
} catch (...) { } catch (...) {
ignoreException(); ignoreException();
} }
try {
if (fdTempRoots != -1) {
fdTempRoots.close();
unlink(fnTempRoots.c_str());
}
} catch (...) {
ignoreException();
}
} }

View file

@ -244,6 +244,10 @@ private:
bool didSetSubstituterEnv; bool didSetSubstituterEnv;
/* The file to which we write our temporary roots. */
Path fnTempRoots;
AutoCloseFD fdTempRoots;
int getSchema(); int getSchema();
void openDB(bool create); void openDB(bool create);