aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/gc.cc
diff options
context:
space:
mode:
authorAndrew Brooks <andrew.brooks@flightaware.com>2022-09-06 17:48:00 -0500
committerAndrew Brooks <andrew.brooks@flightaware.com>2022-09-06 17:48:00 -0500
commit84fe75a12a085c6b4b8d4ac65a048f569de1252b (patch)
tree25f57ac8fc89255f68af7f6476da12ce1558b387 /src/libstore/gc.cc
parent1f041ac54f43093e4f4df1caa630d491ff51c3f8 (diff)
Keep created temp dirs inside store, but protect from GC
Implements the approach suggested by feedback on PR #6994, where tempdir paths are created in the store (now with an exclusive lock). As part of this work, the currently-broken and unused `createTempDirInStore` function is updated to create an exclusive lock on the temp directory in the store. The GC now makes a non-blocking attempt to lock any store directories that "look like" the temp directories created by this function, and if it can't acquire one, ignores the directory.
Diffstat (limited to 'src/libstore/gc.cc')
-rw-r--r--src/libstore/gc.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 4c1a82279..6cd7efbc9 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -619,6 +619,18 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
Path path = storeDir + "/" + std::string(baseName);
Path realPath = realStoreDir + "/" + std::string(baseName);
+ /* There may be temp directories in the store that are still in use
+ by another process. We need to be sure that we can acquire an
+ exclusive lock before deleting them. */
+ AutoCloseFD tmpDirFd;
+ if (baseName.rfind("add-", 0) == 0) {
+ tmpDirFd = open(realPath.c_str(), O_RDONLY | O_DIRECTORY);
+ if (tmpDirFd.get() == -1 || !lockFile(tmpDirFd.get(), ltWrite, false)) {
+ debug("skipping locked tempdir '%s'", realPath);
+ return;
+ }
+ }
+
printInfo("deleting '%1%'", path);
results.paths.insert(path);