diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-04-02 18:26:39 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2020-04-02 18:26:39 +0200 |
commit | 6d6467d376ff8ccc758c9fce1fe6d9b658956598 (patch) | |
tree | 2c3378d5a2c4ad14147b36035c5927bf9464b63c | |
parent | 6cf91d6fbd65d847c1c4a55b4745c1b5f4a7ee9e (diff) |
Move parseTreeInfo()
-rw-r--r-- | src/libexpr/flake/lockfile.cc | 36 | ||||
-rw-r--r-- | src/libfetchers/tree-info.cc | 34 | ||||
-rw-r--r-- | src/libfetchers/tree-info.hh | 2 |
3 files changed, 37 insertions, 35 deletions
diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index 3751e5b90..a40637824 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -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()) diff --git a/src/libfetchers/tree-info.cc b/src/libfetchers/tree-info.cc index 50795e162..42a19cbc8 100644 --- a/src/libfetchers/tree-info.cc +++ b/src/libfetchers/tree-info.cc @@ -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; diff --git a/src/libfetchers/tree-info.hh b/src/libfetchers/tree-info.hh index 25cee445e..3b62151c6 100644 --- a/src/libfetchers/tree-info.hh +++ b/src/libfetchers/tree-info.hh @@ -25,6 +25,8 @@ struct TreeInfo StorePath computeStorePath(Store & store) const; + static TreeInfo fromJson(const nlohmann::json & json); + nlohmann::json toJson() const; }; |