Merge pull request #10413 from Ma27/path-info-all-binary-cache

path-info: print correct path when using `nix path-info --store file://... --all --json`
This commit is contained in:
Théophane Hufschmitt 2024-04-10 15:25:50 +02:00 committed by GitHub
commit a268c0de71
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 1 deletions

View file

@ -43,10 +43,16 @@ static json pathInfoToJSON(
for (auto & storePath : storePaths) { for (auto & storePath : storePaths) {
json jsonObject; json jsonObject;
auto printedStorePath = store.printStorePath(storePath);
try { try {
auto info = store.queryPathInfo(storePath); 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); jsonObject = info->toJSON(store, true, HashFormat::SRI);
if (showClosureSize) { if (showClosureSize) {
@ -74,7 +80,7 @@ static json pathInfoToJSON(
jsonObject = nullptr; jsonObject = nullptr;
} }
jsonAllObjects[store.printStorePath(storePath)] = std::move(jsonObject); jsonAllObjects[printedStorePath] = std::move(jsonObject);
} }
return jsonAllObjects; return jsonAllObjects;
} }

View file

@ -14,6 +14,14 @@ outPath=$(nix-build dependencies.nix --no-out-link)
nix copy --to file://$cacheDir $outPath 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. # Test copying build logs to the binary cache.
expect 1 nix log --store file://$cacheDir $outPath 2>&1 | grep 'is not available' expect 1 nix log --store file://$cacheDir $outPath 2>&1 | grep 'is not available'
nix store copy-log --to file://$cacheDir $outPath nix store copy-log --to file://$cacheDir $outPath