Skip to content

Commit

Permalink
path-info: print correct path when using `nix path-info --store file:…
Browse files Browse the repository at this point in the history
…//... --all --json`

When querying all paths in a binary cache store, the path's representation
is `<hash>-x` (where `x` is the value of `MissingName`) because the .narinfo
filenames only contain the hash.

Before cc46ea1 this worked correctly,
because the entire path info was read and the path from this
representation was printed, i.e. in the form `<hash>-<name>`. Since then
however, the direct result from `queryAllValidPaths()` was used as `path`.

Added a regression test to make sure the behavior remains correct.

(cherry picked from commit c80cd6b)
  • Loading branch information
Ma27 authored and github-actions[bot] committed Apr 10, 2024
1 parent c79d519 commit 8b84348
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/nix/path-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<hash>-x` rather than
// `<hash>-<name>` 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) {
Expand Down Expand Up @@ -74,7 +80,7 @@ static json pathInfoToJSON(
jsonObject = nullptr;
}

jsonAllObjects[store.printStorePath(storePath)] = std::move(jsonObject);
jsonAllObjects[printedStorePath] = std::move(jsonObject);
}
return jsonAllObjects;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/functional/binary-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b84348

Please sign in to comment.