* PathLocks::lockPaths: don't allow reacquiring a lock we already

hold.
This commit is contained in:
Eelco Dolstra 2007-08-28 09:39:03 +00:00
parent 455a7b9577
commit e0d7e47862
2 changed files with 5 additions and 5 deletions

View file

@ -61,6 +61,8 @@ void createSymlink(const Path & link, const Path & target, bool careful)
/* Create directories up to `gcRoot'. */ /* Create directories up to `gcRoot'. */
createDirs(dirOf(link)); createDirs(dirOf(link));
/* !!! shouldn't removing and creating the symlink be atomic? */
/* Remove the old symlink. */ /* Remove the old symlink. */
if (pathExists(link)) { if (pathExists(link)) {
if (careful && (!isLink(link) || !isInStore(readLink(link)))) if (careful && (!isLink(link) || !isInStore(readLink(link))))
@ -68,7 +70,7 @@ void createSymlink(const Path & link, const Path & target, bool careful)
unlink(link.c_str()); unlink(link.c_str());
} }
/* And create the new own. */ /* And create the new one. */
if (symlink(target.c_str(), link.c_str()) == -1) if (symlink(target.c_str(), link.c_str()) == -1)
throw SysError(format("symlinking `%1%' to `%2%'") throw SysError(format("symlinking `%1%' to `%2%'")
% link % target); % link % target);

View file

@ -161,10 +161,8 @@ void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg)
debug(format("locking path `%1%'") % path); debug(format("locking path `%1%'") % path);
if (lockedPaths.find(lockPath) != lockedPaths.end()) { if (lockedPaths.find(lockPath) != lockedPaths.end())
debug(format("already holding lock on `%1%'") % lockPath); throw Error("deadlock: trying to re-acquire self-held lock");
continue;
}
AutoCloseFD fd; AutoCloseFD fd;