With BSD locks we don't have to guard against reading our own
temproots.
This commit is contained in:
Eelco Dolstra 2019-08-02 18:37:55 +02:00
parent e349f2c0a3
commit a2597d5f27
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -221,26 +221,22 @@ void LocalStore::findTempRoots(FDs & fds, Roots & tempRoots, bool censor)
//FDPtr fd(new AutoCloseFD(openLockFile(path, false))); //FDPtr fd(new AutoCloseFD(openLockFile(path, false)));
//if (*fd == -1) continue; //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
/* Try to acquire a write lock without blocking. This can we don't care about its temporary roots. */
only succeed if the owning process has died. In that case if (lockFile(fd->get(), ltWrite, false)) {
we don't care about its temporary roots. */ printError(format("removing stale temporary roots file '%1%'") % path);
if (lockFile(fd->get(), ltWrite, false)) { unlink(path.c_str());
printError(format("removing stale temporary roots file '%1%'") % path); writeFull(fd->get(), "d");
unlink(path.c_str()); continue;
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);
} }
/* 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. */ /* Read the entire file. */
string contents = readFile(fd->get()); string contents = readFile(fd->get());