1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 01:09:37 +01:00

Futher cleans up store object info JSON v2

Since we haven't released v2 yet (2.32 has v1) we can just update this
in-place and avoid version churn.

Note that as a nice side effect of using the standard `Hash` JSON impl,
we don't neeed this `hashFormat` parameter anymore.
This commit is contained in:
John Ericson 2025-11-06 17:07:15 -05:00
parent 9c04c629e5
commit 4f1c8f62c3
16 changed files with 91 additions and 48 deletions

View file

@ -42,7 +42,7 @@ struct NarInfo : ValidPathInfo
std::string to_string(const StoreDirConfig & store) const;
nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const override;
nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo) const override;
static NarInfo fromJSON(const StoreDirConfig & store, const StorePath & path, const nlohmann::json & json);
};

View file

@ -117,7 +117,7 @@ struct UnkeyedValidPathInfo
* @param includeImpureInfo If true, variable elements such as the
* registration time are included.
*/
virtual nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const;
virtual nlohmann::json toJSON(const StoreDirConfig & store, bool includeImpureInfo) const;
static UnkeyedValidPathInfo fromJSON(const StoreDirConfig & store, const nlohmann::json & json);
};

View file

@ -130,11 +130,11 @@ std::string NarInfo::to_string(const StoreDirConfig & store) const
return res;
}
nlohmann::json NarInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const
nlohmann::json NarInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo) const
{
using nlohmann::json;
auto jsonObject = ValidPathInfo::toJSON(store, includeImpureInfo, hashFormat);
auto jsonObject = ValidPathInfo::toJSON(store, includeImpureInfo);
if (includeImpureInfo) {
if (!url.empty())
@ -142,7 +142,7 @@ nlohmann::json NarInfo::toJSON(const StoreDirConfig & store, bool includeImpureI
if (!compression.empty())
jsonObject["compression"] = compression;
if (fileHash)
jsonObject["downloadHash"] = fileHash->to_string(hashFormat, true);
jsonObject["downloadHash"] = *fileHash;
if (fileSize)
jsonObject["downloadSize"] = fileSize;
}
@ -161,17 +161,17 @@ NarInfo NarInfo::fromJSON(const StoreDirConfig & store, const StorePath & path,
auto & obj = getObject(json);
if (json.contains("url"))
res.url = getString(valueAt(obj, "url"));
if (auto * url = get(obj, "url"))
res.url = getString(*url);
if (json.contains("compression"))
res.compression = getString(valueAt(obj, "compression"));
if (auto * compression = get(obj, "compression"))
res.compression = getString(*compression);
if (json.contains("downloadHash"))
res.fileHash = Hash::parseAny(getString(valueAt(obj, "downloadHash")), std::nullopt);
if (auto * downloadHash = get(obj, "downloadHash"))
res.fileHash = *downloadHash;
if (json.contains("downloadSize"))
res.fileSize = getUnsigned(valueAt(obj, "downloadSize"));
if (auto * downloadSize = get(obj, "downloadSize"))
res.fileSize = getUnsigned(*downloadSize);
return res;
}

View file

@ -149,8 +149,7 @@ ValidPathInfo ValidPathInfo::makeFromCA(
return res;
}
nlohmann::json
UnkeyedValidPathInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo, HashFormat hashFormat) const
nlohmann::json UnkeyedValidPathInfo::toJSON(const StoreDirConfig & store, bool includeImpureInfo) const
{
using nlohmann::json;
@ -158,7 +157,7 @@ UnkeyedValidPathInfo::toJSON(const StoreDirConfig & store, bool includeImpureInf
jsonObject["version"] = 2;
jsonObject["narHash"] = narHash.to_string(hashFormat, true);
jsonObject["narHash"] = narHash;
jsonObject["narSize"] = narSize;
{
@ -198,7 +197,7 @@ UnkeyedValidPathInfo UnkeyedValidPathInfo::fromJSON(const StoreDirConfig & store
throw Error("Unsupported path info JSON format version %d, only version 2 is currently supported", version);
}
res.narHash = Hash::parseAny(getString(valueAt(json, "narHash")), std::nullopt);
res.narHash = valueAt(json, "narHash");
res.narSize = getUnsigned(valueAt(json, "narSize"));
try {