mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-27 00:06:16 +02:00
Move parseTreeInfo()
This commit is contained in:
parent
6cf91d6fbd
commit
6d6467d376
3 changed files with 37 additions and 35 deletions
|
@ -32,44 +32,10 @@ FlakeRef getFlakeRef(
|
|||
throw Error("attribute '%s' missing in lock file", version4Attr);
|
||||
}
|
||||
|
||||
static TreeInfo parseTreeInfo(const nlohmann::json & json)
|
||||
{
|
||||
TreeInfo info;
|
||||
|
||||
auto i = json.find("info");
|
||||
if (i != json.end()) {
|
||||
const nlohmann::json & i2(*i);
|
||||
|
||||
auto j = i2.find("narHash");
|
||||
if (j != i2.end())
|
||||
info.narHash = Hash((std::string) *j);
|
||||
else
|
||||
throw Error("attribute 'narHash' missing in lock file");
|
||||
|
||||
j = i2.find("revCount");
|
||||
if (j != i2.end())
|
||||
info.revCount = *j;
|
||||
|
||||
j = i2.find("lastModified");
|
||||
if (j != i2.end())
|
||||
info.lastModified = *j;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
i = json.find("narHash");
|
||||
if (i != json.end()) {
|
||||
info.narHash = Hash((std::string) *i);
|
||||
return info;
|
||||
}
|
||||
|
||||
throw Error("attribute 'info' missing in lock file");
|
||||
}
|
||||
|
||||
LockedNode::LockedNode(const nlohmann::json & json)
|
||||
: lockedRef(getFlakeRef(json, "url", "uri", "locked"))
|
||||
, originalRef(getFlakeRef(json, "originalUrl", "originalUri", "original"))
|
||||
, info(parseTreeInfo(json))
|
||||
, info(TreeInfo::fromJson(json))
|
||||
, isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true)
|
||||
{
|
||||
if (!lockedRef.input->isImmutable())
|
||||
|
|
|
@ -11,6 +11,40 @@ StorePath TreeInfo::computeStorePath(Store & store) const
|
|||
return store.makeFixedOutputPath(true, narHash, "source");
|
||||
}
|
||||
|
||||
TreeInfo TreeInfo::fromJson(const nlohmann::json & json)
|
||||
{
|
||||
TreeInfo info;
|
||||
|
||||
auto i = json.find("info");
|
||||
if (i != json.end()) {
|
||||
const nlohmann::json & i2(*i);
|
||||
|
||||
auto j = i2.find("narHash");
|
||||
if (j != i2.end())
|
||||
info.narHash = Hash((std::string) *j);
|
||||
else
|
||||
throw Error("attribute 'narHash' missing in lock file");
|
||||
|
||||
j = i2.find("revCount");
|
||||
if (j != i2.end())
|
||||
info.revCount = *j;
|
||||
|
||||
j = i2.find("lastModified");
|
||||
if (j != i2.end())
|
||||
info.lastModified = *j;
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
i = json.find("narHash");
|
||||
if (i != json.end()) {
|
||||
info.narHash = Hash((std::string) *i);
|
||||
return info;
|
||||
}
|
||||
|
||||
throw Error("attribute 'info' missing in lock file");
|
||||
}
|
||||
|
||||
nlohmann::json TreeInfo::toJson() const
|
||||
{
|
||||
nlohmann::json json;
|
||||
|
|
|
@ -25,6 +25,8 @@ struct TreeInfo
|
|||
|
||||
StorePath computeStorePath(Store & store) const;
|
||||
|
||||
static TreeInfo fromJson(const nlohmann::json & json);
|
||||
|
||||
nlohmann::json toJson() const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue