summaryrefslogtreecommitdiff
path: root/nix/libstore/pathlocks.cc
diff options
context:
space:
mode:
Diffstat (limited to 'nix/libstore/pathlocks.cc')
-rw-r--r--nix/libstore/pathlocks.cc20
1 files changed, 11 insertions, 9 deletions
diff --git a/nix/libstore/pathlocks.cc b/nix/libstore/pathlocks.cc
index c07f047192..ce4671e209 100644
--- a/nix/libstore/pathlocks.cc
+++ b/nix/libstore/pathlocks.cc
@@ -3,6 +3,8 @@
#include <cerrno>
#include <cstdlib>
+#include <cassert>
+#include <format>
#include <sys/types.h>
#include <sys/stat.h>
@@ -18,7 +20,7 @@ int openLockFile(const Path & path, bool create)
fd = open(path.c_str(), O_RDWR | (create ? O_CREAT : 0), 0600);
if (fd == -1 && (create || errno != ENOENT))
- throw SysError(format("opening lock file `%1%'") % path);
+ throw SysError(std::format("opening lock file `{}'", path));
closeOnExec(fd);
@@ -54,14 +56,14 @@ bool lockFile(int fd, LockType lockType, bool wait)
while (fcntl(fd, F_SETLKW, &lock) != 0) {
checkInterrupt();
if (errno != EINTR)
- throw SysError(format("acquiring/releasing lock"));
+ throw SysError("acquiring/releasing lock");
}
} else {
while (fcntl(fd, F_SETLK, &lock) != 0) {
checkInterrupt();
if (errno == EACCES || errno == EAGAIN) return false;
if (errno != EINTR)
- throw SysError(format("acquiring/releasing lock"));
+ throw SysError("acquiring/releasing lock");
}
}
@@ -109,7 +111,7 @@ bool PathLocks::lockPaths(const PathSet & _paths,
Path path = i;
Path lockPath = path + ".lock";
- debug(format("locking path `%1%'") % path);
+ debug(std::format("locking path `{}'", path));
if (lockedPaths.find(lockPath) != lockedPaths.end())
throw Error("deadlock: trying to re-acquire self-held lock");
@@ -134,19 +136,19 @@ bool PathLocks::lockPaths(const PathSet & _paths,
}
}
- debug(format("lock acquired on `%1%'") % lockPath);
+ debug(std::format("lock acquired on `{}'", lockPath));
/* Check that the lock file hasn't become stale (i.e.,
hasn't been unlinked). */
struct stat st;
if (fstat(fd, &st) == -1)
- throw SysError(format("statting lock file `%1%'") % lockPath);
+ throw SysError(std::format("statting lock file `{}'", lockPath));
if (st.st_size != 0)
/* This lock file has been unlinked, so we're holding
a lock on a deleted file. This means that other
processes may create and acquire a lock on
`lockPath', and proceed. So we must retry. */
- debug(format("open lock file `%1%' has become stale") % lockPath);
+ debug(std::format("open lock file `{}' has become stale", lockPath));
else
break;
}
@@ -178,9 +180,9 @@ void PathLocks::unlock()
lockedPaths.erase(i.second);
if (close(i.first) == -1)
printMsg(lvlError,
- format("error (ignored): cannot close lock file on `%1%'") % i.second);
+ std::format("error (ignored): cannot close lock file on `{}'", i.second));
- debug(format("lock released on `%1%'") % i.second);
+ debug(std::format("lock released on `{}'", i.second));
}
fds.clear();