don't throw an exception for the trivial case of isStorePath()...
Previously if isStorePath() was called on anything other than a top-level /nix/store/some-path, it would throw a BadStorePath exception. This commit duplicates the absolutely trivial check, into maybeParseStorePath(), and leaves exception throwing to parseStorePath(), the function that assumes you're already giving a valid path instead of the one whose purpose is to check if its valid or not... Change-Id: I8dda548f0f88d14ca8c3ee927d64e0ec0681fc7b
This commit is contained in:
parent
ddb4d3fa4c
commit
80bbfe2034
1 changed files with 5 additions and 0 deletions
|
@ -64,6 +64,11 @@ StorePath Store::parseStorePath(std::string_view path) const
|
|||
|
||||
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)) != this->storeDir) {
|
||||
return std::nullopt;
|
||||
}
|
||||
try {
|
||||
return parseStorePath(path);
|
||||
} catch (Error &) {
|
||||
|
|
Loading…
Reference in a new issue