#include "pathlocks.hh" #include "util.hh" #include #include #include #include #include namespace nix { int openLockFile(const Path & path, bool create) { AutoCloseFD fd; fd = open(path.c_str(), O_RDWR | (create ? O_CREAT : 0), 0600); if (fd == -1 && (create || errno != ENOENT)) throw SysError(format("opening lock file `%1%'") % path); closeOnExec(fd); return fd.borrow(); } void deleteLockFile(const Path & path, int fd) { /* Get rid of the lock file. Have to be careful not to introduce races. Write a (meaningless) token to the file to indicate to other processes waiting on this lock that the lock is stale (deleted). */ unlink(path.c_str()); writeFull(fd, "d"); /* Note that the result of unlink() is ignored; removing the lock file is an optimisation, not a necessity. */ } bool lockFile(int fd, LockType lockType, bool wait) { struct flock lock; if (lockType == ltRead) lock.l_type = F_RDLCK; else if (lockType == ltWrite) lock.l_type = F_WRLCK; else if (lockType == ltNone) lock.l_type = F_
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux/gitlog-to-changelog')
0 files changed, 0 insertions, 0 deletions
if (close(i->first) == -1) printMsg(lvlError, format("error (ignored): cannot close lock file on `%1%'") % i->second); debug(format("lock released on `%1%'") % i->second); } fds.clear(); } void PathLocks::setDeletion(bool deletePaths) { this->deletePaths = deletePaths; } bool pathIsLockedByMe(const Path & path) { Path lockPath = path + ".lock"; return lockedPaths.find(lockPath) != lockedPaths.end(); } }