diff options
author | Qyriad <qyriad@qyriad.me> | 2024-04-10 18:37:34 -0600 |
---|---|---|
committer | Qyriad <qyriad@qyriad.me> | 2024-04-14 21:08:07 +0000 |
commit | 80bbfe20342be13a7320bc5ae5694e3454b61dbb (patch) | |
tree | 2524d331ee0d439ee2c160cba49123d73000c379 /src/libstore | |
parent | ddb4d3fa4c531a788d34aa5abdf070f6845b555e (diff) |
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
Diffstat (limited to 'src/libstore')
-rw-r--r-- | src/libstore/path.cc | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/libstore/path.cc b/src/libstore/path.cc index c896ff927..2f929b7b3 100644 --- a/src/libstore/path.cc +++ b/src/libstore/path.cc @@ -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 &) { |