about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-08-02T16·37+0200
committerEelco Dolstra <edolstra@gmail.com>2019-08-02T16·39+0200
commita2597d5f27bc6cfa26343be2f481c8a9d1e22753 (patch)
tree10045fb7d56957d4b7fbf7fc54d131d8c7649aa2 /src
parente349f2c0a370e4dfd09ae51c2cae4db08a834ad5 (diff)
Simplify
With BSD locks we don't have to guard against reading our own
temproots.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/gc.cc32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 2c791efbe67e..366dbfb0a653 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -221,26 +221,22 @@ void LocalStore::findTempRoots(FDs & fds, Roots & tempRoots, bool censor)
         //FDPtr fd(new AutoCloseFD(openLockFile(path, false)));
         //if (*fd == -1) continue;
 
-        if (path != fnTempRoots) {
-
-            /* Try to acquire a write lock without blocking.  This can
-               only succeed if the owning process has died.  In that case
-               we don't care about its temporary roots. */
-            if (lockFile(fd->get(), ltWrite, false)) {
-                printError(format("removing stale temporary roots file '%1%'") % path);
-                unlink(path.c_str());
-                writeFull(fd->get(), "d");
-                continue;
-            }
-
-            /* Acquire a read lock.  This will prevent the owning process
-               from upgrading to a write lock, therefore it will block in
-               addTempRoot(). */
-            debug(format("waiting for read lock on '%1%'") % path);
-            lockFile(fd->get(), ltRead, true);
-
+        /* Try to acquire a write lock without blocking.  This can
+           only succeed if the owning process has died.  In that case
+           we don't care about its temporary roots. */
+        if (lockFile(fd->get(), ltWrite, false)) {
+            printError(format("removing stale temporary roots file '%1%'") % path);
+            unlink(path.c_str());
+            writeFull(fd->get(), "d");
+            continue;
         }
 
+        /* Acquire a read lock.  This will prevent the owning process
+           from upgrading to a write lock, therefore it will block in
+           addTempRoot(). */
+        debug(format("waiting for read lock on '%1%'") % path);
+        lockFile(fd->get(), ltRead, true);
+
         /* Read the entire file. */
         string contents = readFile(fd->get());