diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-07-14T13·27+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-07-14T16·29+0200 |
commit | 3908d3929ceb07cee5983fa647817f0e7aecbd97 (patch) | |
tree | dab9dff2f82f24a84126b4b4a6900fe953aa1b15 /src/libstore/store-api.cc | |
parent | 6438ba22af57edc054e441053a7c3cd5d48e5597 (diff) |
nix path-info: Don't barf on invalid paths
Now you get [ { "path": "/nix/store/fzvliz4j5xzvnd0w5zgw2l0ksqh578yk-bla", "valid": false } ]
Diffstat (limited to 'src/libstore/store-api.cc')
-rw-r--r-- | src/libstore/store-api.cc | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 108e2d4ce9b0..0440af95fa42 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -455,49 +455,55 @@ string Store::makeValidityRegistration(const PathSet & paths, void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths, - bool includeImpureInfo, bool showClosureSize) + bool includeImpureInfo, bool showClosureSize, AllowInvalidFlag allowInvalid) { 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); + jsonPath.attr("path", storePath); - { - auto jsonRefs = jsonPath.list("references"); - for (auto & ref : info->references) - jsonRefs.elem(ref); - } + try { + auto info = queryPathInfo(storePath); + storePath = info->path; - if (info->ca != "") - jsonPath.attr("ca", info->ca); + jsonPath + .attr("narHash", info->narHash.to_string()) + .attr("narSize", info->narSize); - if (showClosureSize) - jsonPath.attr("closureSize", getClosureSize(storePath)); + { + auto jsonRefs = jsonPath.list("references"); + for (auto & ref : info->references) + jsonRefs.elem(ref); + } - if (includeImpureInfo) { + if (info->ca != "") + jsonPath.attr("ca", info->ca); - if (info->deriver != "") - jsonPath.attr("deriver", info->deriver); + if (showClosureSize) + jsonPath.attr("closureSize", getClosureSize(storePath)); - if (info->registrationTime) - jsonPath.attr("registrationTime", info->registrationTime); + if (includeImpureInfo) { - if (info->ultimate) - jsonPath.attr("ultimate", info->ultimate); + 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); + } - if (!info->sigs.empty()) { - auto jsonSigs = jsonPath.list("signatures"); - for (auto & sig : info->sigs) - jsonSigs.elem(sig); } + } catch (InvalidPath &) { + jsonPath.attr("valid", false); } } } |