diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-02 15:52:13 +0000 |
---|---|---|
committer | John Ericson <John.Ericson@Obsidian.Systems> | 2020-06-02 15:52:13 +0000 |
commit | 450dcf2c1b60a36f5ffeab2411805287d122bcdd (patch) | |
tree | d1fe49020e97198147483f42454da46f36e42094 /src/libexpr | |
parent | 6dd471ebf6b9a4996405398093ccb371b8abdf2f (diff) |
Remove `HashType::Unknown`
Instead, `Hash` uses `std::optional<HashType>`. In the future, we may
also make `Hash` itself require a known hash type, encoraging people to
use `std::optional<Hash>` instead.
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/primops.cc | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 8fbcef8c8..63bc949a6 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -718,7 +718,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * if (outputs.size() != 1 || *(outputs.begin()) != "out") throw Error(format("multiple outputs are not supported in fixed-output derivations, at %1%") % posDrvName); - HashType ht = outputHashAlgo.empty() ? HashType::Unknown : parseHashType(outputHashAlgo); + std::optional<HashType> ht = parseHashTypeOpt(outputHashAlgo); Hash h(*outputHash, ht); auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName); @@ -726,7 +726,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * * drv.outputs.insert_or_assign("out", DerivationOutput { std::move(outPath), (ingestionMethod == FileIngestionMethod::Recursive ? "r:" : "") - + printHashType(h.type), + + printHashType(*h.type), h.to_string(Base::Base16, false), }); } @@ -934,14 +934,14 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va static void prim_hashFile(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == HashType::Unknown) + std::optional<HashType> ht = parseHashType(type); + if (!ht) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded Path p = state.coerceToPath(pos, *args[1], context); - mkString(v, hashFile(ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); + mkString(v, hashFile(*ht, state.checkSourcePath(p)).to_string(Base::Base16, false), context); } /* Read a directory (without . or ..) */ @@ -1812,14 +1812,14 @@ static void prim_stringLength(EvalState & state, const Pos & pos, Value * * args static void prim_hashString(EvalState & state, const Pos & pos, Value * * args, Value & v) { string type = state.forceStringNoCtx(*args[0], pos); - HashType ht = parseHashType(type); - if (ht == HashType::Unknown) + std::optional<HashType> ht = parseHashType(type); + if (!ht) throw Error(format("unknown hash type '%1%', at %2%") % type % pos); PathSet context; // discarded string s = state.forceString(*args[1], context, pos); - mkString(v, hashString(ht, s).to_string(Base::Base16, false), context); + mkString(v, hashString(*ht, s).to_string(Base::Base16, false), context); } |