From 588cb0eade0c14acdf4a20dfec5678715cc6542e Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Jun 2006 11:56:49 +0000 Subject: * In `nix-env -i|-u|-e', lock the profile to prevent races between concurrent nix-env operations on the same profile. Fixes NIX-7. --- src/libstore/pathlocks.cc | 11 +++++++---- src/libstore/pathlocks.hh | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/libstore') diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 3beb49aac803..7f7cbdf15a68 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); diff --git a/src/libstore/pathlocks.hh b/src/libstore/pathlocks.hh index 42ebe58df691..2fd0e0d1ed52 100644 --- a/src/libstore/pathlocks.hh +++ b/src/libstore/pathlocks.hh @@ -18,8 +18,10 @@ private: public: PathLocks(); - PathLocks(const PathSet & paths); - void lockPaths(const PathSet & _paths); + PathLocks(const PathSet & paths, + const string & waitMsg = ""); + void lockPaths(const PathSet & _paths, + const string & waitMsg = ""); ~PathLocks(); void setDeletion(bool deletePaths); }; -- cgit 1.4.1