From 76325ce5cda8b4ea3654b58590cce0aed5f4127f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 29 Apr 2019 22:11:14 +0200 Subject: [PATCH] DerivationOutput::parseHashInfo: Return a tuple --- src/libstore/build.cc | 3 +-- src/libstore/derivations.cc | 12 +++++------- src/libstore/derivations.hh | 2 +- src/libstore/local-store.cc | 3 +-- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 53a0c743b..7fa82ae74 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3106,8 +3106,7 @@ void DerivationGoal::registerOutputs() hash). */ if (fixedOutput) { - bool recursive; Hash h; - i.second.parseHashInfo(recursive, h); + auto [recursive, h] = i.second.parseHashInfo(); if (!recursive) { /* The output path should be a regular file without diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 3961126ff..3c5205a87 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -9,21 +9,19 @@ namespace nix { -void DerivationOutput::parseHashInfo(bool & recursive, Hash & hash) const +std::pair DerivationOutput::parseHashInfo() const { - recursive = false; + bool recursive = false; string algo = hashAlgo; - if (string(algo, 0, 2) == "r:") { + if (string(algo, 0, 2) == "r:") recursive = true; - algo = string(algo, 2); - } - HashType hashType = parseHashType(algo); + HashType hashType = parseHashType(recursive ? string(algo, 2) : algo); if (hashType == htUnknown) throw Error(format("unknown hash algorithm '%1%'") % algo); - hash = Hash(this->hash, hashType); + return {recursive, Hash(this->hash, hashType)}; } diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 9753e796d..b21713bad 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -30,7 +30,7 @@ struct DerivationOutput this->hashAlgo = hashAlgo; this->hash = hash; } - void parseHashInfo(bool & recursive, Hash & hash) const; + std::pair parseHashInfo() const; }; typedef std::map DerivationOutputs; diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 485fdd691..0bf1831e4 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -548,8 +548,7 @@ void LocalStore::checkDerivationOutputs(const Path & drvPath, const Derivation & if (out == drv.outputs.end()) throw Error(format("derivation '%1%' does not have an output named 'out'") % drvPath); - bool recursive; Hash h; - out->second.parseHashInfo(recursive, h); + auto [recursive, h] = out->second.parseHashInfo(); Path outPath = makeFixedOutputPath(recursive, h, drvName); StringPairs::const_iterator j = drv.env.find("out");