From 80bbfe20342be13a7320bc5ae5694e3454b61dbb Mon Sep 17 00:00:00 2001 From: Qyriad Date: Wed, 10 Apr 2024 18:37:34 -0600 Subject: [PATCH] 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 --- src/libstore/path.cc | 5 +++++ 1 file changed, 5 insertions(+) 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 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 &) {