From e7c3399ed2e62ecf8a0fb5294f19ffab2061cc04 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 9 May 2023 10:40:10 -0400 Subject: [PATCH] Specialize `LocalOverlayStore::queryPathFromHashPart` With test --- src/libstore/local-overlay-store.cc | 10 ++++++++++ src/libstore/local-overlay-store.hh | 2 ++ tests/overlay-local-store/inner.sh | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/libstore/local-overlay-store.cc b/src/libstore/local-overlay-store.cc index ad1947698..cb409c2bd 100644 --- a/src/libstore/local-overlay-store.cc +++ b/src/libstore/local-overlay-store.cc @@ -98,6 +98,16 @@ bool LocalOverlayStore::isValidPathUncached(const StorePath & path) } +std::optional LocalOverlayStore::queryPathFromHashPart(const std::string & hashPart) +{ + auto res = LocalStore::queryPathFromHashPart(hashPart); + if (res) + return res; + else + return lowerStore->queryPathFromHashPart(hashPart); +} + + void LocalOverlayStore::registerValidPaths(const ValidPathInfos & infos) { // First, get any from lower store so we merge diff --git a/src/libstore/local-overlay-store.hh b/src/libstore/local-overlay-store.hh index daebe8547..88da4ba4a 100644 --- a/src/libstore/local-overlay-store.hh +++ b/src/libstore/local-overlay-store.hh @@ -89,6 +89,8 @@ private: bool isValidPathUncached(const StorePath & path) override; + std::optional queryPathFromHashPart(const std::string & hashPart) override; + void registerValidPaths(const ValidPathInfos & infos) override; void addToStore(const ValidPathInfo & info, Source & source, diff --git a/tests/overlay-local-store/inner.sh b/tests/overlay-local-store/inner.sh index dc8ec8c2c..279f005a9 100755 --- a/tests/overlay-local-store/inner.sh +++ b/tests/overlay-local-store/inner.sh @@ -60,6 +60,14 @@ nix-store --verify-path --store "$storeA" "$path" # Verifying path in merged-store nix-store --verify-path --store "$storeB" "$path" +hashPart=$(echo $path | sed "s^$NIX_STORE_DIR/^^" | sed 's/-.*//') + +# Lower store can find from hash part +[[ $(nix store --store $storeA path-from-hash-part $hashPart) == $path ]] + +# merged store can find from hash part +[[ $(nix store --store $storeB path-from-hash-part $hashPart) == $path ]] + ### Do a redundant add # upper layer should not have it