* Automatically remove temporary root files.

This commit is contained in:
Eelco Dolstra 2005-01-31 21:20:59 +00:00
parent 252c9c91ab
commit 207bdcbe86
3 changed files with 30 additions and 1 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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 */