1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 17:51:15 +02:00

* In `nix-env -i|-u|-e', lock the profile to prevent races between

concurrent nix-env operations on the same profile.  Fixes NIX-7.
This commit is contained in:
Eelco Dolstra 2006-06-15 11:56:49 +00:00
parent 49de87132f
commit 588cb0eade
3 changed files with 26 additions and 6 deletions

View file

@ -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);