From c80cd6bb0684c265f09cf0b17908859a306626fd Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Fri, 5 Apr 2024 16:09:20 +0200 Subject: [PATCH] path-info: print correct path when using `nix path-info --store file://... --all --json` When querying all paths in a binary cache store, the path's representation is `-x` (where `x` is the value of `MissingName`) because the .narinfo filenames only contain the hash. Before cc46ea163024254d0b74646e1b38b19896d40040 this worked correctly, because the entire path info was read and the path from this representation was printed, i.e. in the form `-`. Since then however, the direct result from `queryAllValidPaths()` was used as `path`. Added a regression test to make sure the behavior remains correct. --- src/nix/path-info.cc | 8 +++++++- tests/functional/binary-cache.sh | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc index 5f10cfb61..921b25d7f 100644 --- a/src/nix/path-info.cc +++ b/src/nix/path-info.cc @@ -43,10 +43,16 @@ static json pathInfoToJSON( for (auto & storePath : storePaths) { json jsonObject; + auto printedStorePath = store.printStorePath(storePath); try { auto info = store.queryPathInfo(storePath); + // `storePath` has the representation `-x` rather than + // `-` in case of binary-cache stores & `--all` because we don't + // know the name yet until we've read the NAR info. + printedStorePath = store.printStorePath(info->path); + jsonObject = info->toJSON(store, true, HashFormat::SRI); if (showClosureSize) { @@ -74,7 +80,7 @@ static json pathInfoToJSON( jsonObject = nullptr; } - jsonAllObjects[store.printStorePath(storePath)] = std::move(jsonObject); + jsonAllObjects[printedStorePath] = std::move(jsonObject); } return jsonAllObjects; } diff --git a/tests/functional/binary-cache.sh b/tests/functional/binary-cache.sh index 7c64a115c..2a8d5ccdb 100644 --- a/tests/functional/binary-cache.sh +++ b/tests/functional/binary-cache.sh @@ -14,6 +14,14 @@ outPath=$(nix-build dependencies.nix --no-out-link) nix copy --to file://$cacheDir $outPath +readarray -t paths < <(nix path-info --all --json --store file://$cacheDir | jq 'keys|sort|.[]' -r) +[[ "${#paths[@]}" -eq 3 ]] +for path in "${paths[@]}"; do + [[ "$path" =~ -dependencies-input-0$ ]] \ + || [[ "$path" =~ -dependencies-input-2$ ]] \ + || [[ "$path" =~ -dependencies-top$ ]] +done + # Test copying build logs to the binary cache. expect 1 nix log --store file://$cacheDir $outPath 2>&1 | grep 'is not available' nix store copy-log --to file://$cacheDir $outPath