From e0d7e47862aa1b33292fb8d05e5d50ad4ebf3590 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 28 Aug 2007 09:39:03 +0000 Subject: * PathLocks::lockPaths: don't allow reacquiring a lock we already hold. --- src/libstore/gc.cc | 4 +++- src/libstore/pathlocks.cc | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index 8ce717aaff..e2e6c23fd5 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -61,6 +61,8 @@ void createSymlink(const Path & link, const Path & target, bool careful) /* Create directories up to `gcRoot'. */ createDirs(dirOf(link)); + /* !!! shouldn't removing and creating the symlink be atomic? */ + /* Remove the old symlink. */ if (pathExists(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()); } - /* And create the new own. */ + /* And create the new one. */ if (symlink(target.c_str(), link.c_str()) == -1) throw SysError(format("symlinking `%1%' to `%2%'") % link % target); diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 03ba4f2124..821d4d02fe 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -161,10 +161,8 @@ void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg) debug(format("locking path `%1%'") % path); - if (lockedPaths.find(lockPath) != lockedPaths.end()) { - debug(format("already holding lock on `%1%'") % lockPath); - continue; - } + if (lockedPaths.find(lockPath) != lockedPaths.end()) + throw Error("deadlock: trying to re-acquire self-held lock"); AutoCloseFD fd; -- cgit 1.4.1