aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-09-29 13:05:19 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-09-29 13:05:19 +0200
commit5999978a053b3ec16f448c40b54a1a62ceb82c90 (patch)
treed08c51a3803d7eefb02b046eaed34d679b52088e /src
parentde86abbf3f9f0d18f7506b1d50072597786332ea (diff)
Make Headers an optional argument
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/common-eval-args.cc2
-rw-r--r--src/libexpr/parser.y2
-rw-r--r--src/libexpr/primops/fetchTree.cc4
-rw-r--r--src/libfetchers/fetchers.hh8
-rw-r--r--src/libfetchers/github.cc6
-rw-r--r--src/libfetchers/registry.cc2
-rw-r--r--src/libfetchers/tarball.cc15
-rw-r--r--src/libstore/filetransfer.hh3
-rwxr-xr-xsrc/nix-channel/nix-channel.cc6
9 files changed, 23 insertions, 25 deletions
diff --git a/src/libexpr/common-eval-args.cc b/src/libexpr/common-eval-args.cc
index d71aa22f1..10c1a6975 100644
--- a/src/libexpr/common-eval-args.cc
+++ b/src/libexpr/common-eval-args.cc
@@ -76,7 +76,7 @@ Path lookupFileArg(EvalState & state, string s)
if (isUri(s)) {
return state.store->toRealPath(
fetchers::downloadTarball(
- state.store, resolveUri(s), Headers {}, "source", false).first.storePath);
+ state.store, resolveUri(s), "source", false).first.storePath);
} else if (s.size() > 2 && s.at(0) == '<' && s.at(s.size() - 1) == '>') {
Path p = s.substr(1, s.size() - 2);
return state.findFile(p);
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index e879280c0..a4c84c526 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -718,7 +718,7 @@ std::pair<bool, std::string> EvalState::resolveSearchPathElem(const SearchPathEl
if (isUri(elem.second)) {
try {
res = { true, store->toRealPath(fetchers::downloadTarball(
- store, resolveUri(elem.second), Headers {}, "source", false).first.storePath) };
+ store, resolveUri(elem.second), "source", false).first.storePath) };
} catch (FileTransferError & e) {
logWarning({
.name = "Entry download",
diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc
index 3001957b4..06e8304b8 100644
--- a/src/libexpr/primops/fetchTree.cc
+++ b/src/libexpr/primops/fetchTree.cc
@@ -201,8 +201,8 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
auto storePath =
unpack
- ? fetchers::downloadTarball(state.store, *url, Headers {}, name, (bool) expectedHash).first.storePath
- : fetchers::downloadFile(state.store, *url, Headers{}, name, (bool) expectedHash).storePath;
+ ? fetchers::downloadTarball(state.store, *url, name, (bool) expectedHash).first.storePath
+ : fetchers::downloadFile(state.store, *url, name, (bool) expectedHash).storePath;
auto path = state.store->toRealPath(storePath);
diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh
index 0adc2c9f5..36d44f6e1 100644
--- a/src/libfetchers/fetchers.hh
+++ b/src/libfetchers/fetchers.hh
@@ -118,15 +118,15 @@ struct DownloadFileResult
DownloadFileResult downloadFile(
ref<Store> store,
const std::string & url,
- const Headers & headers,
const std::string & name,
- bool immutable);
+ bool immutable,
+ const Headers & headers = {});
std::pair<Tree, time_t> downloadTarball(
ref<Store> store,
const std::string & url,
- const Headers & headers,
const std::string & name,
- bool immutable);
+ bool immutable,
+ const Headers & headers = {});
}
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc
index 3734c4278..ec99481e1 100644
--- a/src/libfetchers/github.cc
+++ b/src/libfetchers/github.cc
@@ -175,7 +175,7 @@ struct GitArchiveInputScheme : InputScheme
headers.push_back(*url.access_token_header);
}
- auto [tree, lastModified] = downloadTarball(store, url.url, headers, "source", true);
+ auto [tree, lastModified] = downloadTarball(store, url.url, "source", true, headers);
input.attrs.insert_or_assign("lastModified", lastModified);
@@ -215,7 +215,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
auto json = nlohmann::json::parse(
readFile(
store->toRealPath(
- downloadFile(store, url, headers, "source", false).storePath)));
+ downloadFile(store, url, "source", false, headers).storePath)));
auto rev = Hash::parseAny(std::string { json["sha"] }, htSHA1);
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
return rev;
@@ -271,7 +271,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
auto json = nlohmann::json::parse(
readFile(
store->toRealPath(
- downloadFile(store, url, headers, "source", false).storePath)));
+ downloadFile(store, url, "source", false, headers).storePath)));
auto rev = Hash::parseAny(std::string(json[0]["id"]), htSHA1);
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
return rev;
diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc
index 551e7684a..4367ee810 100644
--- a/src/libfetchers/registry.cc
+++ b/src/libfetchers/registry.cc
@@ -145,7 +145,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
auto path = settings.flakeRegistry.get();
if (!hasPrefix(path, "/")) {
- auto storePath = downloadFile(store, path, Headers {}, "flake-registry.json", false).storePath;
+ auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath;
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json");
path = store->toRealPath(storePath);
diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc
index cf6d6e3d2..ca49482a9 100644
--- a/src/libfetchers/tarball.cc
+++ b/src/libfetchers/tarball.cc
@@ -12,9 +12,9 @@ namespace nix::fetchers {
DownloadFileResult downloadFile(
ref<Store> store,
const std::string & url,
- const Headers & headers,
const std::string & name,
- bool immutable)
+ bool immutable,
+ const Headers & headers)
{
// FIXME: check store
@@ -38,7 +38,8 @@ DownloadFileResult downloadFile(
if (cached && !cached->expired)
return useCached();
- FileTransferRequest request(url, headers);
+ FileTransferRequest request(url);
+ request.headers = headers;
if (cached)
request.expectedETag = getStrAttr(cached->infoAttrs, "etag");
FileTransferResult res;
@@ -112,9 +113,9 @@ DownloadFileResult downloadFile(
std::pair<Tree, time_t> downloadTarball(
ref<Store> store,
const std::string & url,
- const Headers & headers,
const std::string & name,
- bool immutable)
+ bool immutable,
+ const Headers & headers)
{
Attrs inAttrs({
{"type", "tarball"},
@@ -130,7 +131,7 @@ std::pair<Tree, time_t> downloadTarball(
getIntAttr(cached->infoAttrs, "lastModified")
};
- auto res = downloadFile(store, url, headers, name, immutable);
+ auto res = downloadFile(store, url, name, immutable, headers);
std::optional<StorePath> unpackedStorePath;
time_t lastModified;
@@ -225,7 +226,7 @@ struct TarballInputScheme : InputScheme
std::pair<Tree, Input> fetch(ref<Store> store, const Input & input) override
{
- auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), Headers {}, "source", false).first;
+ auto tree = downloadTarball(store, getStrAttr(input.attrs, "url"), "source", false).first;
return {std::move(tree), input};
}
};
diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh
index 7e302ff39..c89c51a21 100644
--- a/src/libstore/filetransfer.hh
+++ b/src/libstore/filetransfer.hh
@@ -66,9 +66,6 @@ struct FileTransferRequest
FileTransferRequest(const std::string & uri)
: uri(uri), parentAct(getCurActivity()) { }
- FileTransferRequest(const std::string & uri, Headers headers)
- : uri(uri), headers(headers) { }
-
std::string verb()
{
return data ? "upload" : "download";
diff --git a/src/nix-channel/nix-channel.cc b/src/nix-channel/nix-channel.cc
index 760bbea86..e48f7af9a 100755
--- a/src/nix-channel/nix-channel.cc
+++ b/src/nix-channel/nix-channel.cc
@@ -94,7 +94,7 @@ static void update(const StringSet & channelNames)
// We want to download the url to a file to see if it's a tarball while also checking if we
// got redirected in the process, so that we can grab the various parts of a nix channel
// definition from a consistent location if the redirect changes mid-download.
- auto result = fetchers::downloadFile(store, url, Headers {}, std::string(baseNameOf(url)), false);
+ auto result = fetchers::downloadFile(store, url, std::string(baseNameOf(url)), false);
auto filename = store->toRealPath(result.storePath);
url = result.effectiveUrl;
@@ -119,9 +119,9 @@ static void update(const StringSet & channelNames)
if (!unpacked) {
// Download the channel tarball.
try {
- filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", Headers {}, "nixexprs.tar.xz", false).storePath);
+ filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.xz", "nixexprs.tar.xz", false).storePath);
} catch (FileTransferError & e) {
- filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", Headers {}, "nixexprs.tar.bz2", false).storePath);
+ filename = store->toRealPath(fetchers::downloadFile(store, url + "/nixexprs.tar.bz2", "nixexprs.tar.bz2", false).storePath);
}
}