Merge "libutil: canonPath: error instead of panic on empty path" into main
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(""));
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user