aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorMatthew Bauer <mjbauer95@gmail.com>2020-06-12 10:09:42 -0500
committerMatthew Bauer <mjbauer95@gmail.com>2020-06-12 10:11:16 -0500
commitb260c9ee0325d7a4c78d91e47bd6e2afbde16e28 (patch)
tree176d906367d85d75e96089ce067b776fe232eacf /src/libexpr
parent19aa892f2064d437d32a3c12758d6a623b7ae8e5 (diff)
Add newHashAllowEmpty helper function
This replaces the copy&paste with a helper function in hash.hh.
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc18
-rw-r--r--src/libexpr/primops/fetchTree.cc11
2 files changed, 7 insertions, 22 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index df3d4a459..083c7d398 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -720,12 +720,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
HashType ht = outputHashAlgo.empty() ? htUnknown : parseHashType(outputHashAlgo);
- Hash h;
- if (outputHash->empty()) {
- h = Hash(ht);
- printError("warning: found empty hash, assuming you wanted '%s'", h.to_string());
- } else
- h = Hash(*outputHash, ht);
+ Hash h = newHashAllowEmpty(*outputHash, ht);
auto outPath = state.store->makeFixedOutputPath(ingestionMethod, h, drvName);
if (!jsonObject) drv.env["out"] = state.store->printStorePath(outPath);
@@ -1131,14 +1126,9 @@ static void prim_path(EvalState & state, const Pos & pos, Value * * args, Value
filterFun = attr.value;
} else if (n == "recursive")
method = FileIngestionMethod { state.forceBool(*attr.value, *attr.pos) };
- else if (n == "sha256") {
- auto hashStr = state.forceStringNoCtx(*attr.value, *attr.pos);
- if (hashStr == "") {
- expectedHash = Hash(htSHA256);
- printError("warning: found empty hash, assuming you wanted '%s'", expectedHash.to_string());
- } else
- expectedHash = Hash(hashStr, htSHA256);
- } else
+ else if (n == "sha256")
+ expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
+ else
throw EvalError(format("unsupported argument '%1%' to 'addPath', at %2%") % attr.name % *attr.pos);
}
if (path.empty())
diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc
index 745f65adf..1464aa8b4 100644
--- a/src/libexpr/primops/fetchTree.cc
+++ b/src/libexpr/primops/fetchTree.cc
@@ -102,14 +102,9 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
string n(attr.name);
if (n == "url")
url = state.forceStringNoCtx(*attr.value, *attr.pos);
- else if (n == "sha256") {
- auto hashStr = state.forceStringNoCtx(*attr.value, *attr.pos);
- if (hashStr == "") {
- expectedHash = Hash(htSHA256);
- printError("warning: found empty hash, assuming you wanted '%s'", expectedHash->to_string());
- } else
- expectedHash = Hash(hashStr, htSHA256);
- } else if (n == "name")
+ else if (n == "sha256")
+ expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
+ else if (n == "name")
name = state.forceStringNoCtx(*attr.value, *attr.pos);
else
throw EvalError("unsupported argument '%s' to '%s', at %s",