aboutsummaryrefslogtreecommitdiff
path: root/src/libfetchers
diff options
context:
space:
mode:
Diffstat (limited to 'src/libfetchers')
-rw-r--r--src/libfetchers/fetchers.cc3
-rw-r--r--src/libfetchers/git.cc8
-rw-r--r--src/libfetchers/github.cc8
-rw-r--r--src/libfetchers/mercurial.cc6
-rw-r--r--src/libfetchers/path.cc4
-rw-r--r--src/libfetchers/tarball.cc6
-rw-r--r--src/libfetchers/tree-info.cc2
-rw-r--r--src/libfetchers/tree-info.hh2
8 files changed, 18 insertions, 21 deletions
diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc
index 9174c3de4..b1782feab 100644
--- a/src/libfetchers/fetchers.cc
+++ b/src/libfetchers/fetchers.cc
@@ -35,8 +35,7 @@ std::unique_ptr<Input> inputFromAttrs(const Attrs & attrs)
auto res = inputScheme->inputFromAttrs(attrs2);
if (res) {
if (auto narHash = maybeGetStrAttr(attrs, "narHash"))
- // FIXME: require SRI hash.
- res->narHash = newHashAllowEmpty(*narHash, {});
+ res->narHash = Hash::parseSRI(*narHash);
return res;
}
}
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc
index 75ce5ee8b..909bac78d 100644
--- a/src/libfetchers/git.cc
+++ b/src/libfetchers/git.cc
@@ -225,14 +225,14 @@ struct GitInput : Input
if (isLocal) {
if (!input->rev)
- input->rev = Hash(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), htSHA1);
+ input->rev = Hash::parseAny(chomp(runProgram("git", true, { "-C", actualUrl, "rev-parse", *input->ref })), htSHA1);
repoDir = actualUrl;
} else {
if (auto res = getCache()->lookup(store, mutableAttrs)) {
- auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1);
+ auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1);
if (!rev || rev == rev2) {
input->rev = rev2;
return makeResult(res->first, std::move(res->second));
@@ -301,7 +301,7 @@ struct GitInput : Input
}
if (!input->rev)
- input->rev = Hash(chomp(readFile(localRefFile)), htSHA1);
+ input->rev = Hash::parseAny(chomp(readFile(localRefFile)), htSHA1);
}
bool isShallow = chomp(runProgram("git", true, { "-C", repoDir, "rev-parse", "--is-shallow-repository" })) == "true";
@@ -426,7 +426,7 @@ struct GitInputScheme : InputScheme
input->ref = *ref;
}
if (auto rev = maybeGetStrAttr(attrs, "rev"))
- input->rev = Hash(*rev, htSHA1);
+ input->rev = Hash::parseAny(*rev, htSHA1);
input->shallow = maybeGetBoolAttr(attrs, "shallow").value_or(false);
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc
index 0bee1d6b3..449481092 100644
--- a/src/libfetchers/github.cc
+++ b/src/libfetchers/github.cc
@@ -76,7 +76,7 @@ struct GitHubInput : Input
readFile(
store->toRealPath(
downloadFile(store, url, "source", false).storePath)));
- rev = Hash(std::string { json["sha"] }, htSHA1);
+ rev = Hash::parseAny(std::string { json["sha"] }, htSHA1);
debug("HEAD revision for '%s' is %s", url, rev->gitRev());
}
@@ -140,7 +140,7 @@ struct GitHubInputScheme : InputScheme
if (path.size() == 2) {
} else if (path.size() == 3) {
if (std::regex_match(path[2], revRegex))
- input->rev = Hash(path[2], htSHA1);
+ input->rev = Hash::parseAny(path[2], htSHA1);
else if (std::regex_match(path[2], refRegex))
input->ref = path[2];
else
@@ -152,7 +152,7 @@ struct GitHubInputScheme : InputScheme
if (name == "rev") {
if (input->rev)
throw BadURL("GitHub URL '%s' contains multiple commit hashes", url.url);
- input->rev = Hash(value, htSHA1);
+ input->rev = Hash::parseAny(value, htSHA1);
}
else if (name == "ref") {
if (!std::regex_match(value, refRegex))
@@ -185,7 +185,7 @@ struct GitHubInputScheme : InputScheme
input->repo = getStrAttr(attrs, "repo");
input->ref = maybeGetStrAttr(attrs, "ref");
if (auto rev = maybeGetStrAttr(attrs, "rev"))
- input->rev = Hash(*rev, htSHA1);
+ input->rev = Hash::parseAny(*rev, htSHA1);
return input;
}
};
diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc
index 2e0d4bf4d..29f2a9d5b 100644
--- a/src/libfetchers/mercurial.cc
+++ b/src/libfetchers/mercurial.cc
@@ -167,7 +167,7 @@ struct MercurialInput : Input
});
if (auto res = getCache()->lookup(store, mutableAttrs)) {
- auto rev2 = Hash(getStrAttr(res->first, "rev"), htSHA1);
+ auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1);
if (!rev || rev == rev2) {
input->rev = rev2;
return makeResult(res->first, std::move(res->second));
@@ -210,7 +210,7 @@ struct MercurialInput : Input
runProgram("hg", true, { "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" }));
assert(tokens.size() == 3);
- input->rev = Hash(tokens[0], htSHA1);
+ input->rev = Hash::parseAny(tokens[0], htSHA1);
auto revCount = std::stoull(tokens[1]);
input->ref = tokens[2];
@@ -293,7 +293,7 @@ struct MercurialInputScheme : InputScheme
input->ref = *ref;
}
if (auto rev = maybeGetStrAttr(attrs, "rev"))
- input->rev = Hash(*rev, htSHA1);
+ input->rev = Hash::parseAny(*rev, htSHA1);
return input;
}
};
diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc
index ba2cc192e..1caab4165 100644
--- a/src/libfetchers/path.cc
+++ b/src/libfetchers/path.cc
@@ -101,7 +101,7 @@ struct PathInputScheme : InputScheme
for (auto & [name, value] : url.query)
if (name == "rev")
- input->rev = Hash(value, htSHA1);
+ input->rev = Hash::parseAny(value, htSHA1);
else if (name == "revCount") {
uint64_t revCount;
if (!string2Int(value, revCount))
@@ -129,7 +129,7 @@ struct PathInputScheme : InputScheme
for (auto & [name, value] : attrs)
if (name == "rev")
- input->rev = Hash(getStrAttr(attrs, "rev"), htSHA1);
+ input->rev = Hash::parseAny(getStrAttr(attrs, "rev"), htSHA1);
else if (name == "revCount")
input->revCount = getIntAttr(attrs, "revCount");
else if (name == "lastModified")
diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc
index f5356f0af..6ca51269b 100644
--- a/src/libfetchers/tarball.cc
+++ b/src/libfetchers/tarball.cc
@@ -242,15 +242,13 @@ struct TarballInputScheme : InputScheme
auto hash = input->url.query.find("hash");
if (hash != input->url.query.end()) {
- // FIXME: require SRI hash.
- input->hash = Hash(hash->second);
+ input->hash = Hash::parseSRI(hash->second);
input->url.query.erase(hash);
}
auto narHash = input->url.query.find("narHash");
if (narHash != input->url.query.end()) {
- // FIXME: require SRI hash.
- input->narHash = Hash(narHash->second);
+ input->narHash = Hash::parseSRI(narHash->second);
input->url.query.erase(narHash);
}
diff --git a/src/libfetchers/tree-info.cc b/src/libfetchers/tree-info.cc
index b2d8cfc8d..432aa6182 100644
--- a/src/libfetchers/tree-info.cc
+++ b/src/libfetchers/tree-info.cc
@@ -8,7 +8,7 @@ namespace nix::fetchers {
StorePath TreeInfo::computeStorePath(Store & store) const
{
assert(narHash);
- return store.makeFixedOutputPath(FileIngestionMethod::Recursive, narHash, "source");
+ return store.makeFixedOutputPath(FileIngestionMethod::Recursive, *narHash, "source");
}
}
diff --git a/src/libfetchers/tree-info.hh b/src/libfetchers/tree-info.hh
index 2c7347281..9d1872097 100644
--- a/src/libfetchers/tree-info.hh
+++ b/src/libfetchers/tree-info.hh
@@ -11,7 +11,7 @@ namespace nix::fetchers {
struct TreeInfo
{
- Hash narHash;
+ std::optional<Hash> narHash;
std::optional<uint64_t> revCount;
std::optional<time_t> lastModified;