nix path-info: Don't barf on invalid paths

Now you get

  [
    {
      "path": "/nix/store/fzvliz4j5xzvnd0w5zgw2l0ksqh578yk-bla",
      "valid": false
    }
  ]
This commit is contained in:
Eelco Dolstra 2017-07-14 15:27:21 +02:00
parent 6438ba22af
commit 3908d3929c
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 43 additions and 35 deletions

View file

@ -455,17 +455,19 @@ string Store::makeValidityRegistration(const PathSet & paths,
void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths, void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
bool includeImpureInfo, bool showClosureSize) bool includeImpureInfo, bool showClosureSize, AllowInvalidFlag allowInvalid)
{ {
auto jsonList = jsonOut.list(); auto jsonList = jsonOut.list();
for (auto storePath : storePaths) { for (auto storePath : storePaths) {
auto jsonPath = jsonList.object();
jsonPath.attr("path", storePath);
try {
auto info = queryPathInfo(storePath); auto info = queryPathInfo(storePath);
storePath = info->path; storePath = info->path;
auto jsonPath = jsonList.object();
jsonPath jsonPath
.attr("path", storePath)
.attr("narHash", info->narHash.to_string()) .attr("narHash", info->narHash.to_string())
.attr("narSize", info->narSize); .attr("narSize", info->narSize);
@ -499,6 +501,10 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths
} }
} }
} catch (InvalidPath &) {
jsonPath.attr("valid", false);
}
} }
} }

View file

@ -35,6 +35,7 @@ class JSONPlaceholder;
enum RepairFlag : bool { NoRepair = false, Repair = true }; enum RepairFlag : bool { NoRepair = false, Repair = true };
enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true }; enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true };
enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true }; enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true };
enum AllowInvalidFlag : bool { DisallowInvalid = false, AllowInvalid = true };
/* Size of the hash part of store paths, in base-32 characters. */ /* Size of the hash part of store paths, in base-32 characters. */
@ -488,7 +489,8 @@ public:
included. If showClosureSize is true, the closure size of included. If showClosureSize is true, the closure size of
each path is included. */ each path is included. */
void pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths, void pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
bool includeImpureInfo, bool showClosureSize); bool includeImpureInfo, bool showClosureSize,
AllowInvalidFlag allowInvalid = DisallowInvalid);
/* Return the size of the closure of the specified path, that is, /* Return the size of the closure of the specified path, that is,
the sum of the size of the NAR serialisation of each path in the sum of the size of the NAR serialisation of each path in

View file

@ -69,7 +69,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
store->pathInfoToJSON(jsonRoot, store->pathInfoToJSON(jsonRoot,
// FIXME: preserve order? // FIXME: preserve order?
PathSet(storePaths.begin(), storePaths.end()), PathSet(storePaths.begin(), storePaths.end()),
true, showClosureSize); true, showClosureSize, AllowInvalid);
} }
else { else {