Merge "libutil: canonPath: error instead of panic on empty path" into main

This commit is contained in:
gilice
2025-04-21 15:35:54 +00:00
committed by Lix Systems Gerrit
3 changed files with 4 additions and 6 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ std::optional<StorePath> Store::maybeParseStorePath(std::string_view path) const
{
// If it's not an absolute path, or if the dirname of the path isn't /nix/store
// (or whatever our storeDir is), then it can't be a store path.
if ((path.size() > 0 && path[0] != '/') || dirOf(canonPath(path)) != config().storeDir) {
if (path.size() == 0 || path[0] != '/' || dirOf(canonPath(path)) != config().storeDir) {
return std::nullopt;
}
try {
+2 -4
View File
@@ -42,14 +42,12 @@ Path absPath(Path path, std::optional<PathView> dir, bool resolveSymlinks)
Path canonPath(PathView path, bool resolveSymlinks)
{
assert(path != "");
if (path == "" || path[0] != '/')
throw Error("not an absolute path: '%1%'", path);
std::string s;
s.reserve(256);
if (path[0] != '/')
throw Error("not an absolute path: '%1%'", path);
std::string temp;
/* Count the number of times we follow a symlink and stop at some
+1 -1
View File
@@ -89,7 +89,7 @@ namespace nix {
ASSERT_ANY_THROW(canonPath("."));
ASSERT_ANY_THROW(canonPath(".."));
ASSERT_ANY_THROW(canonPath("../"));
ASSERT_DEATH({ canonPath(""); }, "path != \"\"");
ASSERT_ANY_THROW(canonPath(""));
}
/* ----------------------------------------------------------------------------