From ddaf2750b5af28d56b99f79d3ac20ae11d3464d3 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Tue, 9 May 2023 10:22:38 -0400 Subject: [PATCH] Specialize more methods, fix tests --- src/libstore/local-overlay-store.cc | 30 +++++++++++++++++++++++++---- src/libstore/local-overlay-store.hh | 2 ++ src/libstore/local-store.hh | 2 +- tests/overlay-local-store/inner.sh | 26 ++++++++++++------------- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/libstore/local-overlay-store.cc b/src/libstore/local-overlay-store.cc index a98d2e8fd..ad1947698 100644 --- a/src/libstore/local-overlay-store.cc +++ b/src/libstore/local-overlay-store.cc @@ -4,9 +4,7 @@ namespace nix { Path LocalOverlayStoreConfig::toUpperPath(const StorePath & path) { - auto res = upperLayer + "/" + path.to_string(); - warn("upper path: %s", res); - return res; + return upperLayer + "/" + path.to_string(); } LocalOverlayStore::LocalOverlayStore(const Params & params) @@ -91,7 +89,31 @@ bool LocalOverlayStore::isValidPathUncached(const StorePath & path) { auto res = LocalStore::isValidPathUncached(path); if (res) return res; - return lowerStore->isValidPath(path); + res = lowerStore->isValidPath(path); + if (res) { + // Get path info from lower store so upper DB genuinely has it. + LocalStore::registerValidPath(*lowerStore->queryPathInfo(path)); + } + return res; +} + + +void LocalOverlayStore::registerValidPaths(const ValidPathInfos & infos) +{ + // First, get any from lower store so we merge + { + StorePathSet notInUpper; + for (auto & [p, _] : infos) + if (!LocalStore::isValidPathUncached(p)) // avoid divergence + notInUpper.insert(p); + auto pathsInLower = lowerStore->queryValidPaths(notInUpper); + ValidPathInfos inLower; + for (auto & p : pathsInLower) + inLower.insert_or_assign(p, *lowerStore->queryPathInfo(p)); + LocalStore::registerValidPaths(inLower); + } + // Then do original request + LocalStore::registerValidPaths(infos); } diff --git a/src/libstore/local-overlay-store.hh b/src/libstore/local-overlay-store.hh index c087b3893..daebe8547 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; + void registerValidPaths(const ValidPathInfos & infos) override; + void addToStore(const ValidPathInfo & info, Source & source, RepairFlag repair, CheckSigsFlag checkSigs) override; diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 55add18dd..b61ec3590 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -232,7 +232,7 @@ public: */ void registerValidPath(const ValidPathInfo & info); - void registerValidPaths(const ValidPathInfos & infos); + virtual void registerValidPaths(const ValidPathInfos & infos); unsigned int getProtocol() override; diff --git a/tests/overlay-local-store/inner.sh b/tests/overlay-local-store/inner.sh index d9d3b76cf..dc8ec8c2c 100755 --- a/tests/overlay-local-store/inner.sh +++ b/tests/overlay-local-store/inner.sh @@ -22,7 +22,7 @@ mkdir -p "$TEST_ROOT"/{store-a,store-b,merged-store/nix/store,workdir} nix-store --store "$storeA" --add dummy # Build something in lower store -path=$(nix-build ./hermetic.nix --arg busybox "$busybox" --arg seed 1 --store "$storeA") +path=$(nix-build ./hermetic.nix --arg busybox "$busybox" --arg seed 1 --store "$storeA" --no-out-link) mount -t overlay overlay \ -o lowerdir="$storeA/nix/store" \ @@ -73,17 +73,15 @@ stat $(toRealPath "$storeA/nix/store" "$path") # upper layer should still not have it (no redundant copy) expect 1 stat $(toRealPath "$storeB/nix/store" "$path") -## Ooops something went wrong +### Do a build in overlay store -## ### Do a build in overlay store -## -## path=$(nix-build ./hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB") -## -## # Checking for path in lower layer (should fail) -## expect 1 stat $(toRealPath "$storeA/nix/store" "$path") -## -## # Checking for path in upper layer -## stat $(toRealPath "$storeBTop" "$path") -## -## # Verifying path in overlay store -## nix-store --verify-path --store "$storeB" "$path" +path=$(nix-build ./hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB" --no-out-link) + +# Checking for path in lower layer (should fail) +expect 1 stat $(toRealPath "$storeA/nix/store" "$path") + +# Checking for path in upper layer +stat $(toRealPath "$storeBTop" "$path") + +# Verifying path in overlay store +nix-store --verify-path --store "$storeB" "$path"