diff --git a/lix/libstore/path.cc b/lix/libstore/path.cc index 4bdfb2483..838cb217d 100644 --- a/lix/libstore/path.cc +++ b/lix/libstore/path.cc @@ -77,7 +77,7 @@ std::optional 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 { diff --git a/lix/libutil/file-system.cc b/lix/libutil/file-system.cc index 49fb80bca..b29361719 100644 --- a/lix/libutil/file-system.cc +++ b/lix/libutil/file-system.cc @@ -42,14 +42,12 @@ Path absPath(Path path, std::optional 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 diff --git a/tests/unit/libutil/tests.cc b/tests/unit/libutil/tests.cc index 00fcf8269..bbf285bea 100644 --- a/tests/unit/libutil/tests.cc +++ b/tests/unit/libutil/tests.cc @@ -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("")); } /* ----------------------------------------------------------------------------