diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-06-15 11:56:49 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-06-15 11:56:49 +0000 |
commit | 588cb0eade0c14acdf4a20dfec5678715cc6542e (patch) | |
tree | f37d7546d85b9c262c2905aea42399c145a72943 /src/libstore/pathlocks.cc | |
parent | 49de87132f3f1685fcdd4157f89ca817647028b0 (diff) |
* In `nix-env -i|-u|-e', lock the profile to prevent races between
concurrent nix-env operations on the same profile. Fixes NIX-7.
Diffstat (limited to 'src/libstore/pathlocks.cc')
-rw-r--r-- | src/libstore/pathlocks.cc | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 3beb49aac..7f7cbdf15 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -51,14 +51,14 @@ PathLocks::PathLocks() } -PathLocks::PathLocks(const PathSet & paths) +PathLocks::PathLocks(const PathSet & paths, const string & waitMsg) : deletePaths(false) { - lockPaths(paths); + lockPaths(paths, waitMsg); } -void PathLocks::lockPaths(const PathSet & _paths) +void PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg) { /* May be called only once! */ assert(fds.empty()); @@ -94,7 +94,10 @@ void PathLocks::lockPaths(const PathSet & _paths) throw SysError(format("opening lock file `%1%'") % lockPath); /* Acquire an exclusive lock. */ - lockFile(fd, ltWrite, true); + if (!lockFile(fd, ltWrite, false)) { + if (waitMsg != "") printMsg(lvlError, waitMsg); + lockFile(fd, ltWrite, true); + } debug(format("lock acquired on `%1%'") % lockPath); |