mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
exportReferencesGraph: Export more complete info in JSON format
This writes info about every path in the closure in the same format as ‘nix path-info --json’. Thus it also includes NAR hashes and sizes. Example: [ { "path": "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10", "narHash": "sha256:0ckdc4z20kkmpqdilx0wl6cricxv90lh85xpv2qljppcmz6vzcxl", "narSize": 197648, "references": [ "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10", "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24" ], "closureSize": 20939776 }, { "path": "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24", "narHash": "sha256:1nfn3m3p98y1c0kd0brp80dn9n5mycwgrk183j17rajya0h7gax3", "narSize": 20742128, "references": [ "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24" ], "closureSize": 20742128 } ] Fixes #1134.
This commit is contained in:
parent
6de33a9c67
commit
c2b0d8749f
4 changed files with 90 additions and 50 deletions
|
@ -4,6 +4,7 @@
|
|||
#include "util.hh"
|
||||
#include "nar-info-disk-cache.hh"
|
||||
#include "thread-pool.hh"
|
||||
#include "json.hh"
|
||||
|
||||
#include <future>
|
||||
|
||||
|
@ -439,6 +440,64 @@ string Store::makeValidityRegistration(const PathSet & paths,
|
|||
}
|
||||
|
||||
|
||||
void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
|
||||
bool includeImpureInfo, bool showClosureSize)
|
||||
{
|
||||
auto jsonList = jsonOut.list();
|
||||
|
||||
for (auto storePath : storePaths) {
|
||||
auto info = queryPathInfo(storePath);
|
||||
storePath = info->path;
|
||||
|
||||
auto jsonPath = jsonList.object();
|
||||
jsonPath
|
||||
.attr("path", storePath)
|
||||
.attr("narHash", info->narHash.to_string())
|
||||
.attr("narSize", info->narSize);
|
||||
|
||||
{
|
||||
auto jsonRefs = jsonPath.list("references");
|
||||
for (auto & ref : info->references)
|
||||
jsonRefs.elem(ref);
|
||||
}
|
||||
|
||||
if (info->ca != "")
|
||||
jsonPath.attr("ca", info->ca);
|
||||
|
||||
if (showClosureSize)
|
||||
jsonPath.attr("closureSize", getClosureSize(storePath));
|
||||
|
||||
if (!includeImpureInfo) continue;
|
||||
|
||||
if (info->deriver != "")
|
||||
jsonPath.attr("deriver", info->deriver);
|
||||
|
||||
if (info->registrationTime)
|
||||
jsonPath.attr("registrationTime", info->registrationTime);
|
||||
|
||||
if (info->ultimate)
|
||||
jsonPath.attr("ultimate", info->ultimate);
|
||||
|
||||
if (!info->sigs.empty()) {
|
||||
auto jsonSigs = jsonPath.list("signatures");
|
||||
for (auto & sig : info->sigs)
|
||||
jsonSigs.elem(sig);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned long long Store::getClosureSize(const Path & storePath)
|
||||
{
|
||||
unsigned long long totalSize = 0;
|
||||
PathSet closure;
|
||||
computeFSClosure(storePath, closure, false, false);
|
||||
for (auto & p : closure)
|
||||
totalSize += queryPathInfo(p)->narSize;
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
|
||||
const Store::Stats & Store::getStats()
|
||||
{
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue