From 6bd2c7bb386de16310fa5534275e6e638be60862 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Jul 2015 19:24:28 +0200 Subject: OCD: foreach -> C++11 ranged for --- src/libstore/pathlocks.cc | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/libstore/pathlocks.cc') diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc index 9db37e8f9..1c87034f8 100644 --- a/src/libstore/pathlocks.cc +++ b/src/libstore/pathlocks.cc @@ -60,7 +60,7 @@ bool lockFile(int fd, LockType lockType, bool wait) while (fcntl(fd, F_SETLK, &lock) != 0) { checkInterrupt(); if (errno == EACCES || errno == EAGAIN) return false; - if (errno != EINTR) + if (errno != EINTR) throw SysError(format("acquiring/releasing lock")); } } @@ -94,7 +94,7 @@ bool PathLocks::lockPaths(const PathSet & _paths, const string & waitMsg, bool wait) { assert(fds.empty()); - + /* Note that `fds' is built incrementally so that the destructor will only release those locks that we have already acquired. */ @@ -102,11 +102,10 @@ bool PathLocks::lockPaths(const PathSet & _paths, the same order, thus preventing deadlocks. */ Paths paths(_paths.begin(), _paths.end()); paths.sort(); - + /* Acquire the lock for each path. */ - foreach (Paths::iterator, i, paths) { + for (auto & path : paths) { checkInterrupt(); - Path path = *i; Path lockPath = path + ".lock"; debug(format("locking path ‘%1%’") % path); @@ -115,11 +114,11 @@ bool PathLocks::lockPaths(const PathSet & _paths, throw Error("deadlock: trying to re-acquire self-held lock"); AutoCloseFD fd; - + while (1) { /* Open/create the lock file. */ - fd = openLockFile(lockPath, true); + fd = openLockFile(lockPath, true); /* Acquire an exclusive lock. */ if (!lockFile(fd, ltWrite, false)) { @@ -168,15 +167,15 @@ PathLocks::~PathLocks() void PathLocks::unlock() { - foreach (list::iterator, i, fds) { - if (deletePaths) deleteLockFile(i->second, i->first); + for (auto & i : fds) { + if (deletePaths) deleteLockFile(i.second, i.first); - lockedPaths.erase(i->second); - if (close(i->first) == -1) + lockedPaths.erase(i.second); + if (close(i.first) == -1) printMsg(lvlError, - format("error (ignored): cannot close lock file on ‘%1%’") % i->second); + format("error (ignored): cannot close lock file on ‘%1%’") % i.second); - debug(format("lock released on ‘%1%’") % i->second); + debug(format("lock released on ‘%1%’") % i.second); } fds.clear(); @@ -195,5 +194,5 @@ bool pathIsLockedByMe(const Path & path) return lockedPaths.find(lockPath) != lockedPaths.end(); } - + } -- cgit v1.2.3