diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-02-01 23:33:44 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-02-01 23:33:44 +0100 |
commit | b9d64f931893120834fa54ebf084764d2e22ba33 (patch) | |
tree | 2a4e1abac0f7373a0e5c64d19c89c683d6aa9efd /src/libexpr/flake/lockfile.cc | |
parent | 8451298b35353abafe385124cb55e8d4911032ad (diff) |
Record TreeInfo in the lock file
Necessary for #3253.
Diffstat (limited to 'src/libexpr/flake/lockfile.cc')
-rw-r--r-- | src/libexpr/flake/lockfile.cc | 59 |
1 files changed, 56 insertions, 3 deletions
diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index 60fb914f9..6773b2844 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -44,28 +44,81 @@ 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("rev"); + if (j != i2.end()) + info.rev = Hash((std::string) *j, htSHA1); + + 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"); +} + LockedInput::LockedInput(const nlohmann::json & json) : LockedInputs(json) , ref(getFlakeRef(json, "url", "uri", "resolvedRef")) , originalRef(getFlakeRef(json, "originalUrl", "originalUri", "originalRef")) - , narHash(Hash((std::string) json["narHash"])) + , info(parseTreeInfo(json)) { if (!ref.isImmutable()) throw Error("lockfile contains mutable flakeref '%s'", ref); } +static nlohmann::json treeInfoToJson(const TreeInfo & info) +{ + nlohmann::json json; + assert(info.narHash); + json["narHash"] = info.narHash.to_string(SRI); + if (info.rev) + json["rev"] = info.rev->gitRev(); + if (info.revCount) + json["revCount"] = *info.revCount; + if (info.lastModified) + json["lastModified"] = *info.lastModified; + return json; +} + nlohmann::json LockedInput::toJson() const { auto json = LockedInputs::toJson(); json["originalRef"] = fetchers::attrsToJson(originalRef.toAttrs()); json["resolvedRef"] = fetchers::attrsToJson(ref.toAttrs()); - json["narHash"] = narHash.to_string(SRI); // FIXME + json["info"] = treeInfoToJson(info); return json; } StorePath LockedInput::computeStorePath(Store & store) const { - return store.makeFixedOutputPath(true, narHash, "source"); + assert(info.narHash); + return store.makeFixedOutputPath(true, info.narHash, "source"); } LockedInputs::LockedInputs(const nlohmann::json & json) |