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

remove 'format' from Error constructor calls

This commit is contained in:
Ben Burdette 2020-04-21 17:07:07 -06:00
parent d3052197fe
commit e4fb9a3849
52 changed files with 424 additions and 407 deletions

View file

@ -129,7 +129,7 @@ Path canonPath(const Path & path, bool resolveSymlinks)
string s;
if (path[0] != '/')
throw Error(format("not an absolute path: '%1%'") % path);
throw Error("not an absolute path: '%1%'", path);
string::const_iterator i = path.begin(), end = path.end();
string temp;
@ -165,7 +165,7 @@ Path canonPath(const Path & path, bool resolveSymlinks)
the symlink target might contain new symlinks). */
if (resolveSymlinks && isLink(s)) {
if (++followCount >= maxFollow)
throw Error(format("infinite symlink recursion in path '%1%'") % path);
throw Error("infinite symlink recursion in path '%1%'", path);
temp = absPath(readLink(s), dirOf(s))
+ string(i, end);
i = temp.begin(); /* restart */
@ -226,7 +226,7 @@ struct stat lstat(const Path & path)
{
struct stat st;
if (lstat(path.c_str(), &st))
throw SysError(format("getting status of '%1%'") % path);
throw SysError("getting status of '%1%'", path);
return st;
}
@ -238,7 +238,7 @@ bool pathExists(const Path & path)
res = lstat(path.c_str(), &st);
if (!res) return true;
if (errno != ENOENT && errno != ENOTDIR)
throw SysError(format("getting status of %1%") % path);
throw SysError("getting status of %1%", path);
return false;
}
@ -274,7 +274,7 @@ DirEntries readDirectory(const Path & path)
entries.reserve(64);
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 */
@ -289,7 +289,7 @@ DirEntries readDirectory(const Path & path)
#endif
);
}
if (errno) throw SysError(format("reading directory '%1%'") % path);
if (errno) throw SysError("reading directory '%1%'", path);
return entries;
}
@ -322,7 +322,7 @@ string readFile(const Path & path, bool drain)
{
AutoCloseFD fd = open(path.c_str(), O_RDONLY | O_CLOEXEC);
if (!fd)
throw SysError(format("opening file '%1%'") % path);
throw SysError("opening file '%1%'", path);
return drain ? drainFD(fd.get()) : readFile(fd.get());
}
@ -339,7 +339,7 @@ void writeFile(const Path & path, const string & s, mode_t mode)
{
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
if (!fd)
throw SysError(format("opening file '%1%'") % path);
throw SysError("opening file '%1%'", path);
writeFull(fd.get(), s);
}
@ -348,7 +348,7 @@ void writeFile(const Path & path, Source & source, mode_t mode)
{
AutoCloseFD fd = open(path.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC, mode);
if (!fd)
throw SysError(format("opening file '%1%'") % path);
throw SysError("opening file '%1%'", path);
std::vector<unsigned char> buf(64 * 1024);
@ -396,7 +396,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
struct stat st;
if (lstat(path.c_str(), &st) == -1) {
if (errno == ENOENT) return;
throw SysError(format("getting status of '%1%'") % path);
throw SysError("getting status of '%1%'", path);
}
if (!S_ISDIR(st.st_mode) && st.st_nlink == 1)
@ -407,7 +407,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
const auto PERM_MASK = S_IRUSR | S_IWUSR | S_IXUSR;
if ((st.st_mode & PERM_MASK) != PERM_MASK) {
if (chmod(path.c_str(), st.st_mode | PERM_MASK) == -1)
throw SysError(format("chmod '%1%'") % path);
throw SysError("chmod '%1%'", path);
}
for (auto & i : readDirectory(path))
@ -416,7 +416,7 @@ static void _deletePath(const Path & path, unsigned long long & bytesFreed)
if (remove(path.c_str()) == -1) {
if (errno == ENOENT) return;
throw SysError(format("cannot unlink '%1%'") % path);
throw SysError("cannot unlink '%1%'", path);
}
}
@ -468,12 +468,12 @@ Path createTempDir(const Path & tmpRoot, const Path & prefix,
"wheel", then "tar" will fail to unpack archives that
have the setgid bit set on directories. */
if (chown(tmpDir.c_str(), (uid_t) -1, getegid()) != 0)
throw SysError(format("setting group of directory '%1%'") % tmpDir);
throw SysError("setting group of directory '%1%'", tmpDir);
#endif
return tmpDir;
}
if (errno != EEXIST)
throw SysError(format("creating directory '%1%'") % tmpDir);
throw SysError("creating directory '%1%'", tmpDir);
}
}
@ -555,15 +555,15 @@ Paths createDirs(const Path & path)
if (lstat(path.c_str(), &st) == -1) {
created = createDirs(dirOf(path));
if (mkdir(path.c_str(), 0777) == -1 && errno != EEXIST)
throw SysError(format("creating directory '%1%'") % path);
throw SysError("creating directory '%1%'", path);
st = lstat(path);
created.push_back(path);
}
if (S_ISLNK(st.st_mode) && stat(path.c_str(), &st) == -1)
throw SysError(format("statting symlink '%1%'") % path);
throw SysError("statting symlink '%1%'", path);
if (!S_ISDIR(st.st_mode)) throw Error(format("'%1%' is not a directory") % path);
if (!S_ISDIR(st.st_mode)) throw Error("'%1%' is not a directory", path);
return created;
}
@ -572,7 +572,7 @@ Paths createDirs(const Path & path)
void createSymlink(const Path & target, const Path & link)
{
if (symlink(target.c_str(), link.c_str()))
throw SysError(format("creating symlink from '%1%' to '%2%'") % link % target);
throw SysError("creating symlink from '%1%' to '%2%'", link, target);
}
@ -589,7 +589,7 @@ void replaceSymlink(const Path & target, const Path & link)
}
if (rename(tmp.c_str(), link.c_str()) != 0)
throw SysError(format("renaming '%1%' to '%2%'") % tmp % link);
throw SysError("renaming '%1%' to '%2%'", tmp, link);
break;
}
@ -694,7 +694,7 @@ AutoDelete::~AutoDelete()
deletePath(path);
else {
if (remove(path.c_str()) == -1)
throw SysError(format("cannot unlink '%1%'") % path);
throw SysError("cannot unlink '%1%'", path);
}
}
} catch (...) {
@ -760,7 +760,7 @@ void AutoCloseFD::close()
if (fd != -1) {
if (::close(fd) == -1)
/* This should never happen. */
throw SysError(format("closing file descriptor %1%") % fd);
throw SysError("closing file descriptor %1%", fd);
}
}
@ -920,7 +920,7 @@ void killUser(uid_t uid)
#endif
if (errno == ESRCH) break; /* no more processes */
if (errno != EINTR)
throw SysError(format("cannot kill processes for uid '%1%'") % uid);
throw SysError("cannot kill processes for uid '%1%'", uid);
}
_exit(0);
@ -928,7 +928,7 @@ void killUser(uid_t uid)
int status = pid.wait();
if (status != 0)
throw Error(format("cannot kill processes for uid '%1%': %2%") % uid % statusToString(status));
throw Error("cannot kill processes for uid '%1%': %2%", uid, statusToString(status));
/* !!! We should really do some check to make sure that there are
no processes left running under `uid', but there is no portable
@ -1322,7 +1322,7 @@ void ignoreException()
try {
throw;
} catch (std::exception & e) {
printError(format("error (ignored): %1%") % e.what());
printError("error (ignored): %1%", e.what());
}
}
@ -1440,7 +1440,7 @@ void callFailure(const std::function<void(std::exception_ptr exc)> & failure, st
try {
failure(exc);
} catch (std::exception & e) {
printError(format("uncaught exception: %s") % e.what());
printError("uncaught exception: %s", e.what());
abort();
}
}