aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorBen Burdette <bburdette@gmail.com>2020-04-21 17:07:07 -0600
committerBen Burdette <bburdette@gmail.com>2020-04-21 17:07:07 -0600
commite4fb9a38493a041861fe5c75bc8ddd129a2e5262 (patch)
tree114bedc4dd31da6ebaf6e9b2ebe5f3d6b7b6d274 /src/libstore
parentd3052197feababc312fd874e08ae48050d985eb3 (diff)
remove 'format' from Error constructor calls
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/binary-cache-store.cc8
-rw-r--r--src/libstore/build.cc98
-rw-r--r--src/libstore/builtins/buildenv.cc10
-rw-r--r--src/libstore/builtins/fetchurl.cc4
-rw-r--r--src/libstore/daemon.cc2
-rw-r--r--src/libstore/derivations.cc6
-rw-r--r--src/libstore/download.cc6
-rw-r--r--src/libstore/download.hh6
-rw-r--r--src/libstore/gc.cc44
-rw-r--r--src/libstore/local-binary-cache-store.cc2
-rw-r--r--src/libstore/local-fs-store.cc6
-rw-r--r--src/libstore/local-store.cc48
-rw-r--r--src/libstore/nar-accessor.cc6
-rw-r--r--src/libstore/nar-info.cc2
-rw-r--r--src/libstore/optimise-store.cc24
-rw-r--r--src/libstore/pathlocks.cc8
-rw-r--r--src/libstore/profiles.cc8
-rw-r--r--src/libstore/references.cc2
-rw-r--r--src/libstore/remote-fs-accessor.cc2
-rw-r--r--src/libstore/remote-store.cc4
-rw-r--r--src/libstore/s3-binary-cache-store.cc8
-rw-r--r--src/libstore/sqlite.cc2
-rw-r--r--src/libstore/store-api.cc4
23 files changed, 159 insertions, 151 deletions
diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc
index 3a2d84861..4b7385c6b 100644
--- a/src/libstore/binary-cache-store.cc
+++ b/src/libstore/binary-cache-store.cc
@@ -40,14 +40,14 @@ void BinaryCacheStore::init()
upsertFile(cacheInfoFile, "StoreDir: " + storeDir + "\n", "text/x-nix-cache-info");
} else {
for (auto & line : tokenizeString<Strings>(*cacheInfo, "\n")) {
- size_t colon = line.find(':');
- if (colon == std::string::npos) continue;
+ size_t colon= line.find(':');
+ if (colon ==std::string::npos) continue;
auto name = line.substr(0, colon);
auto value = trim(line.substr(colon + 1, std::string::npos));
if (name == "StoreDir") {
if (value != storeDir)
- throw Error(format("binary cache '%s' is for Nix stores with prefix '%s', not '%s'")
- % getUri() % value % storeDir);
+ throw Error("binary cache '%s' is for Nix stores with prefix '%s', not '%s'",
+ getUri(), value, storeDir);
} else if (name == "WantMassQuery") {
wantMassQuery.setDefault(value == "1" ? "true" : "false");
} else if (name == "Priority") {
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 527d7ac42..2301adb16 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -453,7 +453,7 @@ static void commonChildInit(Pipe & logPipe)
that e.g. ssh cannot open /dev/tty) and it doesn't receive
terminal signals. */
if (setsid() == -1)
- throw SysError(format("creating a new session"));
+ throw SysError("creating a new session");
/* Dup the write side of the logger pipe into stderr. */
if (dup2(logPipe.writeSide.get(), STDERR_FILENO) == -1)
@@ -466,7 +466,7 @@ static void commonChildInit(Pipe & logPipe)
/* Reroute stdin to /dev/null. */
int fdDevNull = open(pathNullDevice.c_str(), O_RDWR);
if (fdDevNull == -1)
- throw SysError(format("cannot open '%1%'") % pathNullDevice);
+ throw SysError("cannot open '%1%'", pathNullDevice);
if (dup2(fdDevNull, STDIN_FILENO) == -1)
throw SysError("cannot dup null device into stdin");
close(fdDevNull);
@@ -488,7 +488,7 @@ void handleDiffHook(
auto diffRes = runProgram(diffHookOptions);
if (!statusOk(diffRes.first))
- throw ExecError(diffRes.first, fmt("diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first)));
+ throw ExecError(diffRes.first, "diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first));
if (diffRes.second != "")
printError(chomp(diffRes.second));
@@ -534,8 +534,8 @@ UserLock::UserLock()
/* Get the members of the build-users-group. */
struct group * gr = getgrnam(settings.buildUsersGroup.get().c_str());
if (!gr)
- throw Error(format("the group '%1%' specified in 'build-users-group' does not exist")
- % settings.buildUsersGroup);
+ throw Error("the group '%1%' specified in 'build-users-group' does not exist",
+ settings.buildUsersGroup);
gid = gr->gr_gid;
/* Copy the result of getgrnam. */
@@ -546,8 +546,8 @@ UserLock::UserLock()
}
if (users.empty())
- throw Error(format("the build users group '%1%' has no members")
- % settings.buildUsersGroup);
+ throw Error("the build users group '%1%' has no members",
+ settings.buildUsersGroup);
/* Find a user account that isn't currently in use for another
build. */
@@ -556,8 +556,8 @@ UserLock::UserLock()
struct passwd * pw = getpwnam(i.c_str());
if (!pw)
- throw Error(format("the user '%1%' in the group '%2%' does not exist")
- % i % settings.buildUsersGroup);
+ throw Error("the user '%1%' in the group '%2%' does not exist",
+ i, settings.buildUsersGroup);
createDirs(settings.nixStateDir + "/userpool");
@@ -565,7 +565,7 @@ UserLock::UserLock()
AutoCloseFD fd = open(fnUserLock.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0600);
if (!fd)
- throw SysError(format("opening user lock '%1%'") % fnUserLock);
+ throw SysError("opening user lock '%1%'", fnUserLock);
if (lockFile(fd.get(), ltWrite, false)) {
fdUserLock = std::move(fd);
@@ -574,8 +574,8 @@ UserLock::UserLock()
/* Sanity check... */
if (uid == getuid() || uid == geteuid())
- throw Error(format("the Nix user should not be a member of '%1%'")
- % settings.buildUsersGroup);
+ throw Error("the Nix user should not be a member of '%1%'",
+ settings.buildUsersGroup);
#if __linux__
/* Get the list of supplementary groups of this build user. This
@@ -585,7 +585,7 @@ UserLock::UserLock()
int err = getgrouplist(pw->pw_name, pw->pw_gid,
supplementaryGIDs.data(), &ngroups);
if (err == -1)
- throw Error(format("failed to get list of supplementary groups for '%1%'") % pw->pw_name);
+ throw Error("failed to get list of supplementary groups for '%1%'", pw->pw_name);
supplementaryGIDs.resize(ngroups);
#endif
@@ -594,9 +594,9 @@ UserLock::UserLock()
}
}
- throw Error(format("all build users are currently in use; "
- "consider creating additional users and adding them to the '%1%' group")
- % settings.buildUsersGroup);
+ throw Error("all build users are currently in use; "
+ "consider creating additional users and adding them to the '%1%' group",
+ settings.buildUsersGroup);
}
@@ -1985,7 +1985,7 @@ void DerivationGoal::startBuilder()
string s = get(drv->env, "exportReferencesGraph").value_or("");
Strings ss = tokenizeString<Strings>(s);
if (ss.size() % 2 != 0)
- throw BuildError(format("odd number of tokens in 'exportReferencesGraph': '%1%'") % s);
+ throw BuildError("odd number of tokens in 'exportReferencesGraph': '%1%'", s);
for (Strings::iterator i = ss.begin(); i != ss.end(); ) {
string fileName = *i++;
static std::regex regex("[A-Za-z_][A-Za-z0-9_.-]*");
@@ -2034,7 +2034,7 @@ void DerivationGoal::startBuilder()
worker.store.computeFSClosure(worker.store.parseStorePath(worker.store.toStorePath(i.second.source)), closure);
} catch (InvalidPath & e) {
} catch (Error & e) {
- throw Error(format("while processing 'sandbox-paths': %s") % e.what());
+ throw Error("while processing 'sandbox-paths': %s", e.what());
}
for (auto & i : closure) {
auto p = worker.store.printStorePath(i);
@@ -2081,10 +2081,10 @@ void DerivationGoal::startBuilder()
printMsg(lvlChatty, format("setting up chroot environment in '%1%'") % chrootRootDir);
if (mkdir(chrootRootDir.c_str(), 0750) == -1)
- throw SysError(format("cannot create '%1%'") % chrootRootDir);
+ throw SysError("cannot create '%1%'", chrootRootDir);
if (buildUser && chown(chrootRootDir.c_str(), 0, buildUser->getGID()) == -1)
- throw SysError(format("cannot change ownership of '%1%'") % chrootRootDir);
+ throw SysError("cannot change ownership of '%1%'", chrootRootDir);
/* Create a writable /tmp in the chroot. Many builders need
this. (Of course they should really respect $TMPDIR
@@ -2128,7 +2128,7 @@ void DerivationGoal::startBuilder()
chmod_(chrootStoreDir, 01775);
if (buildUser && chown(chrootStoreDir.c_str(), 0, buildUser->getGID()) == -1)
- throw SysError(format("cannot change ownership of '%1%'") % chrootStoreDir);
+ throw SysError("cannot change ownership of '%1%'", chrootStoreDir);
for (auto & i : inputPaths) {
auto p = worker.store.printStorePath(i);
@@ -2161,7 +2161,7 @@ void DerivationGoal::startBuilder()
if (needsHashRewrite()) {
if (pathExists(homeDir))
- throw Error(format("directory '%1%' exists; please remove it") % homeDir);
+ throw Error("directory '%1%' exists; please remove it", homeDir);
/* We're not doing a chroot build, but we have some valid
output paths. Since we can't just overwrite or delete
@@ -2206,8 +2206,7 @@ void DerivationGoal::startBuilder()
if (line == "extra-sandbox-paths" || line == "extra-chroot-dirs") {
state = stExtraChrootDirs;
} else {
- throw Error(format("unknown pre-build hook command '%1%'")
- % line);
+ throw Error("unknown pre-build hook command '%1%'", line);
}
} else if (state == stExtraChrootDirs) {
if (line == "") {
@@ -2967,7 +2966,7 @@ void DerivationGoal::chownToBuilder(const Path & path)
{
if (!buildUser) return;
if (chown(path.c_str(), buildUser->getUID(), buildUser->getGID()) == -1)
- throw SysError(format("cannot change ownership of '%1%'") % path);
+ throw SysError("cannot change ownership of '%1%'", path);
}
@@ -3104,7 +3103,7 @@ void DerivationGoal::runChild()
/* Bind-mount chroot directory to itself, to treat it as a
different filesystem from /, as needed for pivot_root. */
if (mount(chrootRootDir.c_str(), chrootRootDir.c_str(), 0, MS_BIND, 0) == -1)
- throw SysError(format("unable to bind mount '%1%'") % chrootRootDir);
+ throw SysError("unable to bind mount '%1%'", chrootRootDir);
/* Bind-mount the sandbox's Nix store onto itself so that
we can mark it as a "shared" subtree, allowing bind
@@ -3238,16 +3237,16 @@ void DerivationGoal::runChild()
/* Do the chroot(). */
if (chdir(chrootRootDir.c_str()) == -1)
- throw SysError(format("cannot change directory to '%1%'") % chrootRootDir);
+ throw SysError("cannot change directory to '%1%'", chrootRootDir);
if (mkdir("real-root", 0) == -1)
throw SysError("cannot create real-root directory");
if (pivot_root(".", "real-root") == -1)
- throw SysError(format("cannot pivot old root directory onto '%1%'") % (chrootRootDir + "/real-root"));
+ throw SysError("cannot pivot old root directory onto '%1%'", (chrootRootDir + "/real-root"));
if (chroot(".") == -1)
- throw SysError(format("cannot change root directory to '%1%'") % chrootRootDir);
+ throw SysError("cannot change root directory to '%1%'", chrootRootDir);
if (umount2("real-root", MNT_DETACH) == -1)
throw SysError("cannot unmount real root filesystem");
@@ -3268,7 +3267,7 @@ void DerivationGoal::runChild()
#endif
if (chdir(tmpDirInSandbox.c_str()) == -1)
- throw SysError(format("changing into '%1%'") % tmpDir);
+ throw SysError("changing into '%1%'", tmpDir);
/* Close all other file descriptors. */
closeMostFDs({STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO});
@@ -3407,9 +3406,9 @@ void DerivationGoal::runChild()
sandboxProfile += "(allow file-read* file-write* process-exec\n";
for (auto & i : dirsInChroot) {
if (i.first != i.second.source)
- throw Error(format(
- "can't map '%1%' to '%2%': mismatched impure paths not supported on Darwin")
- % i.first % i.second.source);
+ throw Error(
+ "can't map '%1%' to '%2%': mismatched impure paths not supported on Darwin",
+ i.first, i.second.source);
string path = i.first;
struct stat st;
@@ -3500,7 +3499,7 @@ void DerivationGoal::runChild()
else if (drv->builder == "builtin:unpack-channel")
builtinUnpackChannel(drv2);
else
- throw Error(format("unsupported builtin function '%1%'") % string(drv->builder, 8));
+ throw Error("unsupported builtin function '%1%'", string(drv->builder, 8));
_exit(0);
} catch (std::exception & e) {
writeFull(STDERR_FILENO, "error: " + string(e.what()) + "\n");
@@ -3510,7 +3509,7 @@ void DerivationGoal::runChild()
execve(builder, stringsToCharPtrs(args).data(), stringsToCharPtrs(envStrs).data());
- throw SysError(format("executing '%1%'") % drv->builder);
+ throw SysError("executing '%1%'", drv->builder);
} catch (std::exception & e) {
writeFull(STDERR_FILENO, "\1while setting up the build environment: " + string(e.what()) + "\n");
@@ -3595,7 +3594,7 @@ void DerivationGoal::registerOutputs()
replaceValidPath(path, actualPath);
else
if (buildMode != bmCheck && rename(actualPath.c_str(), worker.store.toRealPath(path).c_str()) == -1)
- throw SysError(format("moving build output '%1%' from the sandbox to the Nix store") % path);
+ throw SysError("moving build output '%1%' from the sandbox to the Nix store", path);
}
if (buildMode != bmCheck) actualPath = worker.store.toRealPath(path);
}
@@ -3616,13 +3615,13 @@ void DerivationGoal::registerOutputs()
user. */
if ((!S_ISLNK(st.st_mode) && (st.st_mode & (S_IWGRP | S_IWOTH))) ||
(buildUser && st.st_uid != buildUser->getUID()))
- throw BuildError(format("suspicious ownership or permission on '%1%'; rejecting this build output") % path);
+ throw BuildError("suspicious ownership or permission on '%1%'; rejecting this build output", path);
#endif
/* Apply hash rewriting if necessary. */
bool rewritten = false;
if (!outputRewrites.empty()) {
- printError(format("warning: rewriting hashes in '%1%'; cross fingers") % path);
+ printError("warning: rewriting hashes in '%1%'; cross fingers", path);
/* Canonicalise first. This ensures that the path we're
rewriting doesn't contain a hard link to /etc/shadow or
@@ -3654,7 +3653,8 @@ void DerivationGoal::registerOutputs()
/* The output path should be a regular file without execute permission. */
if (!S_ISREG(st.st_mode) || (st.st_mode & S_IXUSR) != 0)
throw BuildError(
- format("output path '%1%' should be a non-executable regular file") % path);
+ "output path '%1%' should be a non-executable regular file",
+ path);
}
/* Check the hash. In hash mode, move the path produced by
@@ -3715,7 +3715,7 @@ void DerivationGoal::registerOutputs()
Path dst = worker.store.toRealPath(path + checkSuffix);
deletePath(dst);
if (rename(actualPath.c_str(), dst.c_str()))
- throw SysError(format("renaming '%1%' to '%2%'") % actualPath % dst);
+ throw SysError("renaming '%1%' to '%2%'", actualPath, dst);
handleDiffHook(
buildUser ? buildUser->getUID() : getuid(),
@@ -4014,7 +4014,7 @@ Path DerivationGoal::openLogFile()
settings.compressLog ? ".bz2" : "");
fdLogFile = open(logFileName.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0666);
- if (!fdLogFile) throw SysError(format("creating log file '%1%'") % logFileName);
+ if (!fdLogFile) throw SysError("creating log file '%1%'", logFileName);
logFileSink = std::make_shared<FdSink>(fdLogFile.get());
@@ -4522,7 +4522,6 @@ void SubstitutionGoal::handleEOF(int fd)
if (fd == outPipe.readSide.get()) worker.wakeUp(shared_from_this());
}
-
//////////////////////////////////////////////////////////////////////
@@ -4739,9 +4738,9 @@ void Worker::run(const Goals & _topGoals)
if (!children.empty() || !waitingForAWhile.empty())
waitForInput();
else {
- if (awake.empty() && 0 == settings.maxBuildJobs) throw Error(
- "unable to start any build; either increase '--max-jobs' "
- "or enable remote builds");
+ if (awake.empty() && 0 == settings.maxBuildJobs)
+ throw Error("unable to start any build; either increase '--max-jobs' "
+ "or enable remote builds");
assert(!awake.empty());
}
}
@@ -4754,7 +4753,6 @@ void Worker::run(const Goals & _topGoals)
assert(!settings.keepGoing || children.empty());
}
-
void Worker::waitForInput()
{
printMsg(lvlVomit, "waiting for children");
@@ -4895,6 +4893,9 @@ void Worker::waitForInput()
}
+
+
+
unsigned int Worker::exitStatus()
{
/*
@@ -4994,7 +4995,6 @@ void LocalStore::buildPaths(const std::vector<StorePathWithOutputs> & drvPaths,
throw Error(worker.exitStatus(), "build of %s failed", showPaths(failed));
}
-
BuildResult LocalStore::buildDerivation(const StorePath & drvPath, const BasicDerivation & drv,
BuildMode buildMode)
{
@@ -5055,4 +5055,8 @@ void LocalStore::repairPath(const StorePath & path)
}
+
}
+
+
+
diff --git a/src/libstore/builtins/buildenv.cc b/src/libstore/builtins/buildenv.cc
index 1b802d908..000769094 100644
--- a/src/libstore/builtins/buildenv.cc
+++ b/src/libstore/builtins/buildenv.cc
@@ -72,15 +72,15 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
if (!S_ISDIR(lstat(target).st_mode))
throw Error("collision between '%1%' and non-directory '%2%'", srcFile, target);
if (unlink(dstFile.c_str()) == -1)
- throw SysError(format("unlinking '%1%'") % dstFile);
+ throw SysError("unlinking '%1%'", dstFile);
if (mkdir(dstFile.c_str(), 0755) == -1)
- throw SysError(format("creating directory '%1%'"));
+ throw SysError("creating directory '%1%'", dstFile);
createLinks(state, target, dstFile, state.priorities[dstFile]);
createLinks(state, srcFile, dstFile, priority);
continue;
}
} else if (errno != ENOENT)
- throw SysError(format("getting status of '%1%'") % dstFile);
+ throw SysError("getting status of '%1%'", dstFile);
}
else {
@@ -99,11 +99,11 @@ static void createLinks(State & state, const Path & srcDir, const Path & dstDir,
if (prevPriority < priority)
continue;
if (unlink(dstFile.c_str()) == -1)
- throw SysError(format("unlinking '%1%'") % dstFile);
+ throw SysError("unlinking '%1%'", dstFile);
} else if (S_ISDIR(dstSt.st_mode))
throw Error("collision between non-directory '%1%' and directory '%2%'", srcFile, dstFile);
} else if (errno != ENOENT)
- throw SysError(format("getting status of '%1%'") % dstFile);
+ throw SysError("getting status of '%1%'", dstFile);
}
createSymlink(srcFile, dstFile);
diff --git a/src/libstore/builtins/fetchurl.cc b/src/libstore/builtins/fetchurl.cc
index f6ae5d2e6..223ed1fba 100644
--- a/src/libstore/builtins/fetchurl.cc
+++ b/src/libstore/builtins/fetchurl.cc
@@ -18,7 +18,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
auto getAttr = [&](const string & name) {
auto i = drv.env.find(name);
- if (i == drv.env.end()) throw Error(format("attribute '%s' missing") % name);
+ if (i == drv.env.end()) throw Error("attribute '%s' missing", name);
return i->second;
};
@@ -54,7 +54,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
auto executable = drv.env.find("executable");
if (executable != drv.env.end() && executable->second == "1") {
if (chmod(storePath.c_str(), 0755) == -1)
- throw SysError(format("making '%1%' executable") % storePath);
+ throw SysError("making '%1%' executable", storePath);
}
};
diff --git a/src/libstore/daemon.cc b/src/libstore/daemon.cc
index d985f151b..f8b449e5e 100644
--- a/src/libstore/daemon.cc
+++ b/src/libstore/daemon.cc
@@ -747,7 +747,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
}
default:
- throw Error(format("invalid operation %1%") % op);
+ throw Error("invalid operation %1%", op);
}
}
diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc
index 973ddc86a..f35b8cc43 100644
--- a/src/libstore/derivations.cc
+++ b/src/libstore/derivations.cc
@@ -87,7 +87,7 @@ static void expect(std::istream & str, const string & s)
char s2[s.size()];
str.read(s2, s.size());
if (string(s2, s.size()) != s)
- throw FormatError(format("expected string '%1%'") % s);
+ throw FormatError("expected string '%1%'", s);
}
@@ -114,7 +114,7 @@ static Path parsePath(std::istream & str)
{
string s = parseString(str);
if (s.size() == 0 || s[0] != '/')
- throw FormatError(format("bad path '%1%' in derivation") % s);
+ throw FormatError("bad path '%1%' in derivation", s);
return s;
}
@@ -196,7 +196,7 @@ Derivation readDerivation(const Store & store, const Path & drvPath)
try {
return parseDerivation(store, readFile(drvPath));
} catch (FormatError & e) {
- throw Error(format("error parsing derivation '%1%': %2%") % drvPath % e.msg());
+ throw Error("error parsing derivation '%1%': %2%", drvPath, e.msg());
}
}
diff --git a/src/libstore/download.cc b/src/libstore/download.cc
index 5967d0425..7d0cb449b 100644
--- a/src/libstore/download.cc
+++ b/src/libstore/download.cc
@@ -113,7 +113,7 @@ struct CurlDownloader : public Downloader
if (requestHeaders) curl_slist_free_all(requestHeaders);
try {
if (!done)
- fail(DownloadError(Interrupted, format("download of '%s' was interrupted") % request.uri));
+ fail(DownloadError(Interrupted, "download of '%s' was interrupted", request.uri));
} catch (...) {
ignoreException();
}
@@ -518,7 +518,7 @@ struct CurlDownloader : public Downloader
int running;
CURLMcode mc = curl_multi_perform(curlm, &running);
if (mc != CURLM_OK)
- throw nix::Error(format("unexpected error from curl_multi_perform(): %s") % curl_multi_strerror(mc));
+ throw nix::Error("unexpected error from curl_multi_perform(): %s", curl_multi_strerror(mc));
/* Set the promises of any finished requests. */
CURLMsg * msg;
@@ -548,7 +548,7 @@ struct CurlDownloader : public Downloader
vomit("download thread waiting for %d ms", sleepTimeMs);
mc = curl_multi_wait(curlm, extraFDs, 1, sleepTimeMs, &numfds);
if (mc != CURLM_OK)
- throw nix::Error(format("unexpected error from curl_multi_wait(): %s") % curl_multi_strerror(mc));
+ throw nix::Error("unexpected error from curl_multi_wait(): %s", curl_multi_strerror(mc));
nextWakeup = std::chrono::steady_clock::time_point();
diff --git a/src/libstore/download.hh b/src/libstore/download.hh
index 5a131c704..8141928d2 100644
--- a/src/libstore/download.hh
+++ b/src/libstore/download.hh
@@ -128,8 +128,10 @@ class DownloadError : public Error
{
public:
Downloader::Error error;
- DownloadError(Downloader::Error error, const FormatOrString & fs)
- : Error(fs), error(error)
+
+ template<typename... Args>
+ DownloadError(Downloader::Error error, const Args & ... args)
+ : Error(args...), error(error)
{ }
};
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index 0c3d89611..27bd3f3e9 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -38,7 +38,7 @@ AutoCloseFD LocalStore::openGCLock(LockType lockType)
AutoCloseFD fdGCLock = open(fnGCLock.c_str(), O_RDWR | O_CREAT | O_CLOEXEC, 0600);
if (!fdGCLock)
- throw SysError(format("opening global GC lock '%1%'") % fnGCLock);
+ throw SysError("opening global GC lock '%1%'", fnGCLock);
if (!lockFile(fdGCLock.get(), lockType, false)) {
printError(format("waiting for the big garbage collector lock..."));
@@ -65,8 +65,8 @@ static void makeSymlink(const Path & link, const Path & target)
/* Atomically replace the old one. */
if (rename(tempLink.c_str(), link.c_str()) == -1)
- throw SysError(format("cannot rename '%1%' to '%2%'")
- % tempLink % link);
+ throw SysError("cannot rename '%1%' to '%2%'",
+ tempLink , link);
}
@@ -91,15 +91,15 @@ Path LocalFSStore::addPermRoot(const StorePath & storePath,
Path gcRoot(canonPath(_gcRoot));
if (isInStore(gcRoot))
- throw Error(format(
+ throw Error(
"creating a garbage collector root (%1%) in the Nix store is forbidden "
- "(are you running nix-build inside the store?)") % gcRoot);
+ "(are you running nix-build inside the store?)", gcRoot);
if (indirect) {
/* Don't clobber the link if it already exists and doesn't
point to the Nix store. */
if (pathExists(gcRoot) && (!isLink(gcRoot) || !isInStore(readLink(gcRoot))))
- throw Error(format("cannot create symlink '%1%'; already exists") % gcRoot);
+ throw Error("cannot create symlink '%1%'; already exists", gcRoot);
makeSymlink(gcRoot, printStorePath(storePath));
addIndirectRoot(gcRoot);
}
@@ -109,10 +109,10 @@ Path LocalFSStore::addPermRoot(const StorePath & storePath,
Path rootsDir = canonPath((format("%1%/%2%") % stateDir % gcRootsDir).str());
if (string(gcRoot, 0, rootsDir.size() + 1) != rootsDir + "/")
- throw Error(format(
+ throw Error(
"path '%1%' is not a valid garbage collector root; "
- "it's not in the directory '%2%'")
- % gcRoot % rootsDir);
+ "it's not in the directory '%2%'",
+ gcRoot, rootsDir);
}
if (baseNameOf(gcRoot) == std::string(storePath.to_string()))
@@ -170,7 +170,7 @@ void LocalStore::addTempRoot(const StorePath & path)
way. */
struct stat st;
if (fstat(state->fdTempRoots.get(), &st) == -1)
- throw SysError(format("statting '%1%'") % fnTempRoots);
+ throw SysError("statting '%1%'", fnTempRoots);
if (st.st_size == 0) break;
/* The garbage collector deleted this file before we could
@@ -211,7 +211,7 @@ void LocalStore::findTempRoots(FDs & fds, Roots & tempRoots, bool censor)
if (!*fd) {
/* It's okay if the file has disappeared. */
if (errno == ENOENT) continue;
- throw SysError(format("opening temporary roots file '%1%'") % path);
+ throw SysError("opening temporary roots file '%1%'", path);
}
/* This should work, but doesn't, for some reason. */
@@ -222,7 +222,7 @@ void LocalStore::findTempRoots(FDs & fds, Roots & tempRoots, bool censor)
only succeed if the owning process has died. In that case
we don't care about its temporary roots. */
if (lockFile(fd->get(), ltWrite, false)) {
- printError(format("removing stale temporary roots file '%1%'") % path);
+ printError("removing stale temporary roots file '%1%'", path);
unlink(path.c_str());
writeFull(fd->get(), "d");
continue;
@@ -398,7 +398,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
if (!fdDir) {
if (errno == ENOENT || errno == EACCES)
continue;
- throw SysError(format("opening %1%") % fdStr);
+ throw SysError("opening %1%", fdStr);
}
struct dirent * fd_ent;
while (errno = 0, fd_ent = readdir(fdDir.get())) {
@@ -408,7 +408,7 @@ void LocalStore::findRuntimeRoots(Roots & roots, bool censor)
if (errno) {
if (errno == ESRCH)
continue;
- throw SysError(format("iterating /proc/%1%/fd") % ent->d_name);
+ throw SysError("iterating /proc/%1%/fd", ent->d_name);
}
fdDir.reset();
@@ -536,7 +536,7 @@ void LocalStore::deletePathRecursive(GCState & state, const Path & path)
struct stat st;
if (lstat(realPath.c_str(), &st)) {
if (errno == ENOENT) return;
- throw SysError(format("getting status of %1%") % realPath);
+ throw SysError("getting status of %1%", realPath);
}
printInfo(format("deleting '%1%'") % path);
@@ -554,10 +554,10 @@ void LocalStore::deletePathRecursive(GCState & state, const Path & path)
// size.
try {
if (chmod(realPath.c_str(), st.st_mode | S_IWUSR) == -1)
- throw SysError(format("making '%1%' writable") % realPath);
+ throw SysError("making '%1%' writable", realPath);
Path tmp = trashDir + "/" + std::string(baseNameOf(path));
if (rename(realPath.c_str(), tmp.c_str()))
- throw SysError(format("unable to rename '%1%' to '%2%'") % realPath % tmp);
+ throw SysError("unable to rename '%1%' to '%2%'", realPath, tmp);
state.bytesInvalidated += size;
} catch (SysError & e) {
if (e.errNo == ENOSPC) {
@@ -676,7 +676,7 @@ void LocalStore::tryToDelete(GCState & state, const Path & path)
void LocalStore::removeUnusedLinks(const GCState & state)
{
AutoCloseDir dir(opendir(linksDir.c_str()));
- if (!dir) throw SysError(format("opening directory '%1%'") % linksDir);
+ if (!dir) throw SysError("opening directory '%1%'", linksDir);
long long actualSize = 0, unsharedSize = 0;
@@ -689,7 +689,7 @@ void LocalStore::removeUnusedLinks(const GCState & state)
struct stat st;
if (lstat(path.c_str(), &st) == -1)
- throw SysError(format("statting '%1%'") % path);
+ throw SysError("statting '%1%'", path);
if (st.st_nlink != 1) {
actualSize += st.st_size;
@@ -700,14 +700,14 @@ void LocalStore::removeUnusedLinks(const GCState & state)
printMsg(lvlTalkative, format("deleting unused link '%1%'") % path);
if (unlink(path.c_str()) == -1)
- throw SysError(format("deleting '%1%'") % path);
+ throw SysError("deleting '%1%'", path);
state.results.bytesFreed += st.st_size;
}
struct stat st;
if (stat(linksDir.c_str(), &st) == -1)
- throw SysError(format("statting '%1%'") % linksDir);
+ throw SysError("statting '%1%'", linksDir);
long long overhead = st.st_blocks * 512ULL;
printInfo(format("note: currently hard linking saves %.2f MiB")
@@ -801,7 +801,7 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
try {
AutoCloseDir dir(opendir(realStoreDir.c_str()));
- if (!dir) throw SysError(format("opening directory '%1%'") % realStoreDir);
+ if (!dir) throw SysError("opening directory '%1%'", realStoreDir);
/* Read the store and immediately delete all paths that
aren't valid. When using --max-freed etc., deleting
diff --git a/src/libstore/local-binary-cache-store.cc b/src/libstore/local-binary-cache-store.cc
index 363be1443..48aca478c 100644
--- a/src/libstore/local-binary-cache-store.cc
+++ b/src/libstore/local-binary-cache-store.cc
@@ -74,7 +74,7 @@ static void atomicWrite(const Path & path, const std::string & s)
AutoDelete del(tmp, false);
writeFile(tmp, s);
if (rename(tmp.c_str(), path.c_str()))
- throw SysError(format("renaming '%1%' to '%2%'") % tmp % path);
+ throw SysError("renaming '%1%' to '%2%'", tmp, path);
del.cancel();
}
diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc
index aa5abd835..2d564a0d7 100644
--- a/src/libstore/local-fs-store.cc
+++ b/src/libstore/local-fs-store.cc
@@ -22,7 +22,7 @@ struct LocalStoreAccessor : public FSAccessor
{
Path storePath = store->toStorePath(path);
if (!store->isValidPath(store->parseStorePath(storePath)))
- throw InvalidPath(format("path '%1%' is not a valid store path") % storePath);
+ throw InvalidPath("path '%1%' is not a valid store path", storePath);
return store->getRealStoreDir() + std::string(path, store->storeDir.size());
}
@@ -33,11 +33,11 @@ struct LocalStoreAccessor : public FSAccessor
struct stat st;
if (lstat(realPath.c_str(), &st)) {
if (errno == ENOENT || errno == ENOTDIR) return {Type::tMissing, 0, false};
- throw SysError(format("getting status of '%1%'") % path);
+ throw SysError("getting status of '%1%'", path);
}
if (!S_ISREG(st.st_mode) && !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode))
- throw Error(format("file '%1%' has unsupported type") % path);
+ throw Error("file '%1%' has unsupported type", path);
return {
S_ISREG(st.st_mode) ? Type::tRegular :
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index ae7513ad8..db5a3b53c 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -92,13 +92,13 @@ LocalStore::LocalStore(const Params & params)
else {
struct stat st;
if (stat(realStoreDir.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % realStoreDir);
+ throw SysError("getting attributes of path '%1%'", realStoreDir);
if (st.st_uid != 0 || st.st_gid != gr->gr_gid || (st.st_mode & ~S_IFMT) != perm) {
if (chown(realStoreDir.c_str(), 0, gr->gr_gid) == -1)
- throw SysError(format("changing ownership of path '%1%'") % realStoreDir);
+ throw SysError("changing ownership of path '%1%'", realStoreDir);
if (chmod(realStoreDir.c_str(), perm) == -1)
- throw SysError(format("changing permissions on path '%1%'") % realStoreDir);
+ throw SysError("changing permissions on path '%1%'", realStoreDir);
}
}
}
@@ -109,12 +109,12 @@ LocalStore::LocalStore(const Params & params)
struct stat st;
while (path != "/") {
if (lstat(path.c_str(), &st))
- throw SysError(format("getting status of '%1%'") % path);
+ throw SysError("getting status of '%1%'", path);
if (S_ISLNK(st.st_mode))
- throw Error(format(
+ throw Error(
"the path '%1%' is a symlink; "
- "this is not allowed for the Nix store and its parent directories")
- % path);
+ "this is not allowed for the Nix store and its parent directories",
+ path);
path = dirOf(path);
}
}
@@ -155,8 +155,8 @@ LocalStore::LocalStore(const Params & params)
upgrade. */
int curSchema = getSchema();
if (curSchema > nixSchemaVersion)
- throw Error(format("current Nix store schema is version %1%, but I only support %2%")
- % curSchema % nixSchemaVersion);
+ throw Error("current Nix store schema is version %1%, but I only support %2%",
+ curSchema, nixSchemaVersion);
else if (curSchema == 0) { /* new store */
curSchema = nixSchemaVersion;
@@ -284,7 +284,7 @@ int LocalStore::getSchema()
if (pathExists(schemaPath)) {
string s = readFile(schemaPath);
if (!string2Int(s, curSchema))
- throw Error(format("'%1%' is corrupt") % schemaPath);
+ throw Error("'%1%' is corrupt", schemaPath);
}
return curSchema;
}
@@ -293,7 +293,7 @@ int LocalStore::getSchema()
void LocalStore::openDB(State & state, bool create)
{
if (access(dbDir.c_str(), R_OK | W_OK))
- throw SysError(format("Nix database directory '%1%' is not writable") % dbDir);
+ throw SysError("Nix database directory '%1%' is not writable", dbDir);
/* Open the Nix database. */
string dbPath = dbDir + "/db.sqlite";
@@ -367,7 +367,7 @@ void LocalStore::makeStoreWritable()
throw SysError("setting up a private mount namespace");
if (mount(0, realStoreDir.c_str(), "none", MS_REMOUNT | MS_BIND, 0) == -1)
- throw SysError(format("remounting %1% writable") % realStoreDir);
+ throw SysError("remounting %1% writable", realStoreDir);
}
#endif
}
@@ -388,7 +388,7 @@ static void canonicaliseTimestampAndPermissions(const Path & path, const struct
| 0444
| (st.st_mode & S_IXUSR ? 0111 : 0);
if (chmod(path.c_str(), mode) == -1)
- throw SysError(format("changing mode of '%1%' to %2$o") % path % mode);
+ throw SysError("changing mode of '%1%' to %2$o", path, mode);
}
}
@@ -406,7 +406,7 @@ static void canonicaliseTimestampAndPermissions(const Path & path, const struct
#else
if (!S_ISLNK(st.st_mode) && utimes(path.c_str(), times) == -1)
#endif
- throw SysError(format("changing modification time of '%1%'") % path);
+ throw SysError("changing modification time of '%1%'", path);
}
}
@@ -415,7 +415,7 @@ void canonicaliseTimestampAndPermissions(const Path & path)
{
struct stat st;
if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % path);
+ throw SysError("getting attributes of path '%1%'", path);
canonicaliseTimestampAndPermissions(path, st);
}
@@ -430,17 +430,17 @@ static void canonicalisePathMetaData_(const Path & path, uid_t fromUid, InodesSe
setattrlist() to remove other attributes as well. */
if (lchflags(path.c_str(), 0)) {
if (errno != ENOTSUP)
- throw SysError(format("clearing flags of path '%1%'") % path);
+ throw SysError("clearing flags of path '%1%'", path);
}
#endif
struct stat st;
if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % path);
+ throw SysError("getting attributes of path '%1%'", path);
/* Really make sure that the path is of a supported type. */
if (!(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode) || S_ISLNK(st.st_mode)))
- throw Error(format("file '%1%' has an unsupported type") % path);
+ throw Error("file '%1%' has an unsupported type", path);
#if __linux__
/* Remove extended attributes / ACLs. */
@@ -474,7 +474,7 @@ static void canonicalisePathMetaData_(const Path & path, uid_t fromUid, InodesSe
if (fromUid != (uid_t) -1 && st.st_uid != fromUid) {
assert(!S_ISDIR(st.st_mode));
if (inodesSeen.find(Inode(st.st_dev, st.st_ino)) == inodesSeen.end())
- throw BuildError(format("invalid ownership on file '%1%'") % path);
+ throw BuildError("invalid ownership on file '%1%'", path);
mode_t mode = st.st_mode & ~S_IFMT;
assert(S_ISLNK(st.st_mode) || (st.st_uid == geteuid() && (mode == 0444 || mode == 0555) && st.st_mtime == mtimeStore));
return;
@@ -498,8 +498,8 @@ static void canonicalisePathMetaData_(const Path & path, uid_t fromUid, InodesSe
if (!S_ISLNK(st.st_mode) &&
chown(path.c_str(), geteuid(), getegid()) == -1)
#endif
- throw SysError(format("changing owner of '%1%' to %2%")
- % path % geteuid());
+ throw SysError("changing owner of '%1%' to %2%",
+ path, geteuid());
}
if (S_ISDIR(st.st_mode)) {
@@ -518,11 +518,11 @@ void canonicalisePathMetaData(const Path & path, uid_t fromUid, InodesSeen & ino
be a symlink, since we can't change its ownership. */
struct stat st;
if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % path);
+ throw SysError("getting attributes of path '%1%'", path);
if (st.st_uid != geteuid()) {
assert(S_ISLNK(st.st_mode));
- throw Error(format("wrong ownership of top-level store path '%1%'") % path);
+ throw Error("wrong ownership of top-level store path '%1%'", path);
}
}
@@ -1392,7 +1392,7 @@ static void makeMutable(const Path & path)
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (fd == -1) {
if (errno == ELOOP) return; // it's a symlink
- throw SysError(format("opening file '%1%'") % path);
+ throw SysError("opening file '%1%'", path);
}
unsigned int flags = 0, old;
diff --git a/src/libstore/nar-accessor.cc b/src/libstore/nar-accessor.cc
index b74480684..ca663d837 100644
--- a/src/libstore/nar-accessor.cc
+++ b/src/libstore/nar-accessor.cc
@@ -184,7 +184,7 @@ struct NarAccessor : public FSAccessor
auto i = get(path);
if (i.type != FSAccessor::Type::tDirectory)
- throw Error(format("path '%1%' inside NAR file is not a directory") % path);
+ throw Error("path '%1%' inside NAR file is not a directory", path);
StringSet res;
for (auto & child : i.children)
@@ -197,7 +197,7 @@ struct NarAccessor : public FSAccessor
{
auto i = get(path);
if (i.type != FSAccessor::Type::tRegular)
- throw Error(format("path '%1%' inside NAR file is not a regular file") % path);
+ throw Error("path '%1%' inside NAR file is not a regular file", path);
if (getNarBytes) return getNarBytes(i.start, i.size);
@@ -209,7 +209,7 @@ struct NarAccessor : public FSAccessor
{
auto i = get(path);
if (i.type != FSAccessor::Type::tSymlink)
- throw Error(format("path '%1%' inside NAR file is not a symlink") % path);
+ throw Error("path '%1%' inside NAR file is not a symlink", path);
return i.target;
}
};
diff --git a/src/libstore/nar-info.cc b/src/libstore/nar-info.cc
index 1375094b5..fbdcd7786 100644
--- a/src/libstore/nar-info.cc
+++ b/src/libstore/nar-info.cc
@@ -7,7 +7,7 @@ NarInfo::NarInfo(const Store & store, const std::string & s, const std::string &
: ValidPathInfo(StorePath::dummy.clone()) // FIXME: hack
{
auto corrupt = [&]() {
- throw Error(format("NAR info file '%1%' is corrupt") % whence);
+ throw Error("NAR info file '%1%' is corrupt", whence);
};
auto parseHashField = [&](const string & s) {
diff --git a/src/libstore/optimise-store.cc b/src/libstore/optimise-store.cc
index 8ac382e9d..f9cf2bb6b 100644
--- a/src/libstore/optimise-store.cc
+++ b/src/libstore/optimise-store.cc
@@ -19,9 +19,9 @@ static void makeWritable(const Path & path)
{
struct stat st;
if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % path);
+ throw SysError("getting attributes of path '%1%'", path);
if (chmod(path.c_str(), st.st_mode | S_IWUSR) == -1)
- throw SysError(format("changing writability of '%1%'") % path);
+ throw SysError("changing writability of '%1%'", path);
}
@@ -47,7 +47,7 @@ LocalStore::InodeHash LocalStore::loadInodeHash()
InodeHash inodeHash;
AutoCloseDir dir(opendir(linksDir.c_str()));
- if (!dir) throw SysError(format("opening directory '%1%'") % linksDir);
+ if (!dir) throw SysError("opening directory '%1%'", linksDir);
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
@@ -55,7 +55,7 @@ LocalStore::InodeHash LocalStore::loadInodeHash()
// We don't care if we hit non-hash files, anything goes
inodeHash.insert(dirent->d_ino);
}
- if (errno) throw SysError(format("reading directory '%1%'") % linksDir);
+ if (errno) throw SysError("reading directory '%1%'", linksDir);
printMsg(lvlTalkative, format("loaded %1% hash inodes") % inodeHash.size());
@@ -68,7 +68,7 @@ Strings LocalStore::readDirectoryIgnoringInodes(const Path & path, const InodeHa
Strings names;
AutoCloseDir dir(opendir(path.c_str()));
- if (!dir) throw SysError(format("opening directory '%1%'") % path);
+ if (!dir) throw SysError("opening directory '%1%'", path);
struct dirent * dirent;
while (errno = 0, dirent = readdir(dir.get())) { /* sic */
@@ -83,7 +83,7 @@ Strings LocalStore::readDirectoryIgnoringInodes(const Path & path, const InodeHa
if (name == "." || name == "..") continue;
names.push_back(name);
}
- if (errno) throw SysError(format("reading directory '%1%'") % path);
+ if (errno) throw SysError("reading directory '%1%'", path);
return names;
}
@@ -96,7 +96,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
struct stat st;
if (lstat(path.c_str(), &st))
- throw SysError(format("getting attributes of path '%1%'") % path);
+ throw SysError("getting attributes of path '%1%'", path);
#if __APPLE__
/* HFS/macOS has some undocumented security feature disabling hardlinking for
@@ -130,7 +130,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
NixOS (example: $fontconfig/var/cache being modified). Skip
those files. FIXME: check the modification time. */
if (S_ISREG(st.st_mode) && (st.st_mode & S_IWUSR)) {
- printError(format("skipping suspicious writable file '%1%'") % path);
+ printError("skipping suspicious writable file '%1%'", path);
return;
}
@@ -186,7 +186,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
current file with a hard link to that file. */
struct stat stLink;
if (lstat(linkPath.c_str(), &stLink))
- throw SysError(format("getting attributes of path '%1%'") % linkPath);
+ throw SysError("getting attributes of path '%1%'", linkPath);
if (st.st_ino == stLink.st_ino) {
debug(format("'%1%' is already linked to '%2%'") % path % linkPath);
@@ -194,7 +194,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
}
if (st.st_size != stLink.st_size) {
- printError(format("removing corrupted link '%1%'") % linkPath);
+ printError("removing corrupted link '%1%'", linkPath);
unlink(linkPath.c_str());
goto retry;
}
@@ -229,7 +229,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
/* Atomically replace the old file with the new hard link. */
if (rename(tempLink.c_str(), path.c_str()) == -1) {
if (unlink(tempLink.c_str()) == -1)
- printError(format("unable to unlink '%1%'") % tempLink);
+ printError("unable to unlink '%1%'", tempLink);
if (errno == EMLINK) {
/* Some filesystems generate too many links on the rename,
rather than on the original link. (Probably it
@@ -238,7 +238,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
debug("'%s' has reached maximum number of links", linkPath);
return;
}
- throw SysError(format("cannot rename '%1%' to '%2%'") % tempLink % path);
+ throw SysError("cannot rename '%1%' to '%2%'", tempLink, path);
}
stats.filesLinked++;
diff --git a/src/libstore/pathlocks.cc b/src/libstore/pathlocks.cc
index 2635e3940..52d430ffd 100644
--- a/src/libstore/pathlocks.cc
+++ b/src/libstore/pathlocks.cc
@@ -20,7 +20,7 @@ AutoCloseFD openLockFile(const Path & path, bool create)
fd = open(path.c_str(), O_CLOEXEC | O_RDWR | (create ? O_CREAT : 0), 0600);
if (!fd && (create || errno != ENOENT))
- throw SysError(format("opening lock file '%1%'") % path);
+ throw SysError("opening lock file '%1%'", path);
return fd;
}
@@ -51,7 +51,7 @@ bool lockFile(int fd, LockType lockType, bool wait)
while (flock(fd, type) != 0) {
checkInterrupt();
if (errno != EINTR)
- throw SysError(format("acquiring/releasing lock"));
+ throw SysError("acquiring/releasing lock");
else
return false;
}
@@ -60,7 +60,7 @@ bool lockFile(int fd, LockType lockType, bool wait)
checkInterrupt();
if (errno == EWOULDBLOCK) return false;
if (errno != EINTR)
- throw SysError(format("acquiring/releasing lock"));
+ throw SysError("acquiring/releasing lock");
}
}
@@ -124,7 +124,7 @@ bool PathLocks::lockPaths(const PathSet & paths,
hasn't been unlinked). */
struct stat st;
if (fstat(fd.get(), &st) == -1)
- throw SysError(format("statting lock file '%1%'") % lockPath);
+ throw SysError("statting lock file '%1%'", 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
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index 2bef51878..6cfe393a4 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -50,7 +50,7 @@ Generations findGenerations(Path profile, int & curGen)
gen.number = n;
struct stat st;
if (lstat(gen.path.c_str(), &st) != 0)
- throw SysError(format("statting '%1%'") % gen.path);
+ throw SysError("statting '%1%'", gen.path);
gen.creationTime = st.st_mtime;
gens.push_back(gen);
}
@@ -117,7 +117,7 @@ Path createGeneration(ref<LocalFSStore> store, Path profile, Path outPath)
static void removeFile(const Path & path)
{
if (remove(path.c_str()) == -1)
- throw SysError(format("cannot unlink '%1%'") % path);
+ throw SysError("cannot unlink '%1%'", path);
}
@@ -149,7 +149,7 @@ void deleteGenerations(const Path & profile, const std::set<unsigned int> & gens
Generations gens = findGenerations(profile, curGen);
if (gensToDelete.find(curGen) != gensToDelete.end())
- throw Error(format("cannot delete current generation of profile %1%'") % profile);
+ throw Error("cannot delete current generation of profile %1%'", profile);
for (auto & i : gens) {
if (gensToDelete.find(i.number) == gensToDelete.end()) continue;
@@ -226,7 +226,7 @@ void deleteGenerationsOlderThan(const Path & profile, const string & timeSpec, b
int days;
if (!string2Int(strDays, days) || days < 1)
- throw Error(format("invalid number of days specifier '%1%'") % timeSpec);
+ throw Error("invalid number of days specifier '%1%'", timeSpec);
time_t oldTime = curTime - days * 24 * 3600;
diff --git a/src/libstore/references.cc b/src/libstore/references.cc
index 102e15921..a10d536a3 100644
--- a/src/libstore/references.cc
+++ b/src/libstore/references.cc
@@ -92,7 +92,7 @@ PathSet scanForReferences(const string & path,
auto baseName = std::string(baseNameOf(i));
string::size_type pos = baseName.find('-');
if (pos == string::npos)
- throw Error(format("bad reference '%1%'") % i);
+ throw Error("bad reference '%1%'", i);
string s = string(baseName, 0, pos);
assert(s.size() == refLength);
assert(backMap.find(s) == backMap.end());
diff --git a/src/libstore/remote-fs-accessor.cc b/src/libstore/remote-fs-accessor.cc
index 5a2d103b9..9277a8e6b 100644
--- a/src/libstore/remote-fs-accessor.cc
+++ b/src/libstore/remote-fs-accessor.cc
@@ -51,7 +51,7 @@ std::pair<ref<FSAccessor>, Path> RemoteFSAccessor::fetch(const Path & path_)
std::string restPath = std::string(path, storePath.size());
if (!store->isValidPath(store->parseStorePath(storePath)))
- throw InvalidPath(format("path '%1%' is not a valid store path") % storePath);
+ throw InvalidPath("path '%1%' is not a valid store path", storePath);
auto i = nars.find(storePath);
if (i != nars.end()) return {i->second, restPath};
diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc
index 8c55da268..0f8126aee 100644
--- a/src/libstore/remote-store.cc
+++ b/src/libstore/remote-store.cc
@@ -116,11 +116,11 @@ ref<RemoteStore::Connection> UDSRemoteStore::openConnection()
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
if (socketPath.size() + 1 >= sizeof(addr.sun_path))
- throw Error(format("socket path '%1%' is too long") % socketPath);
+ throw Error("socket path '%1%' is too long", socketPath);
strcpy(addr.sun_path, socketPath.c_str());
if (::connect(conn->fd.get(), (struct sockaddr *) &addr, sizeof(addr)) == -1)
- throw SysError(format("cannot connect to daemon at '%1%'") % socketPath);
+ throw SysError("cannot connect to daemon at '%1%'", socketPath);
conn->from.fd = conn->fd.get();
conn->to.fd = conn->fd.get();
diff --git a/src/libstore/s3-binary-cache-store.cc b/src/libstore/s3-binary-cache-store.cc
index f2e4b63e0..0326821f6 100644
--- a/src/libstore/s3-binary-cache-store.cc
+++ b/src/libstore/s3-binary-cache-store.cc
@@ -32,8 +32,10 @@ namespace nix {
struct S3Error : public Error
{
Aws::S3::S3Errors err;
- S3Error(Aws::S3::S3Errors err, const FormatOrString & fs)
- : Error(fs), err(err) { };
+
+ template<typename... Args>
+ S3Error(Aws::S3::S3Errors err, const Args & ... args)
+ : Error(args...), err(err) { };
};
/* Helper: given an Outcome<R, E>, return R in case of success, or
@@ -249,7 +251,7 @@ struct S3BinaryCacheStoreImpl : public S3BinaryCacheStore
// If bucket listing is disabled, 404s turn into 403s
|| error.GetErrorType() == Aws::S3::S3Errors::ACCESS_DENIED)
return false;
- throw Error(format("AWS error fetching '%s': %s") % path % error.GetMessage());
+ throw Error("AWS error fetching '%s': %s", path, error.GetMessage());
}
return true;
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index eb1daafc5..3407e5826 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -29,7 +29,7 @@ SQLite::SQLite(const Path & path, bool create)
{
if (sqlite3_open_v2(path.c_str(), &db,
SQLITE_OPEN_READWRITE | (create ? SQLITE_OPEN_CREATE : 0), 0) != SQLITE_OK)
- throw Error(format("cannot open SQLite database '%s'") % path);
+ throw Error("cannot open SQLite database '%s'", path);
if (sqlite3_busy_timeout(db, 60 * 60 * 1000) != SQLITE_OK)
throwSQLiteError(db, "setting timeout");
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index b9e894a9a..a04d5013e 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -22,7 +22,7 @@ bool Store::isInStore(const Path & path) const
Path Store::toStorePath(const Path & path) const
{
if (!isInStore(path))
- throw Error(format("path '%1%' is not in the Nix store") % path);
+ throw Error("path '%1%' is not in the Nix store", path);
Path::size_type slash = path.find('/', storeDir.size() + 1);
if (slash == Path::npos)
return path;
@@ -40,7 +40,7 @@ Path Store::followLinksToStore(std::string_view _path) const
path = absPath(target, dirOf(path));
}
if (!isInStore(path))
- throw Error(format("path '%1%' is not in the Nix store") % path);
+ throw Error("path '%1%' is not in the Nix store", path);
return path;
}