1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 13:41:15 +02:00

Make nix path-info --json return an object not array

Before it returned a list of JSON objects with store object information,
including the path in each object. Now, it maps the paths to JSON
objects with the metadata sans path.

This matches how `nix derivation show` works.

Quite hillariously, none of our existing functional tests caught this
change to `path-info --json` though they did use it. So just new
functional tests need to be added.
This commit is contained in:
John Ericson 2023-10-22 21:12:54 -04:00
parent a7212e169b
commit cc46ea1630
14 changed files with 108 additions and 54 deletions

View file

@ -148,7 +148,7 @@ ValidPathInfo::ValidPathInfo(
}
nlohmann::json ValidPathInfo::toJSON(
nlohmann::json UnkeyedValidPathInfo::toJSON(
const Store & store,
bool includeImpureInfo,
HashFormat hashFormat) const
@ -157,8 +157,6 @@ nlohmann::json ValidPathInfo::toJSON(
auto jsonObject = json::object();
jsonObject["path"] = store.printStorePath(path);
jsonObject["valid"] = true;
jsonObject["narHash"] = narHash.to_string(hashFormat, true);
jsonObject["narSize"] = narSize;
@ -190,21 +188,17 @@ nlohmann::json ValidPathInfo::toJSON(
return jsonObject;
}
ValidPathInfo ValidPathInfo::fromJSON(
UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(
const Store & store,
const nlohmann::json & json)
{
using nlohmann::detail::value_t;
ValidPathInfo res {
StorePath(StorePath::dummy),
UnkeyedValidPathInfo res {
Hash(Hash::dummy),
};
ensureType(json, value_t::object);
res.path = store.parseStorePath(
static_cast<const std::string &>(
ensureType(valueAt(json, "path"), value_t::string)));
res.narHash = Hash::parseAny(
static_cast<const std::string &>(
ensureType(valueAt(json, "narHash"), value_t::string)),