libstore: remove FileTransfer::enqueueDownload
it's no longer needed. `download` can do everything `enqueueDownload`
did, and a lot more. e.g. not block the calling thread, for instance.
Change-Id: I4b36235ed707c92d117b4c33efa3db50d26f9a84
This commit is contained in:
parent
c68f0cdf00
commit
d65838a900
|
@ -45,7 +45,9 @@ DownloadFileResult downloadFile(
|
||||||
FileTransferResult res;
|
FileTransferResult res;
|
||||||
std::string data;
|
std::string data;
|
||||||
try {
|
try {
|
||||||
std::tie(res, data) = getFileTransfer()->enqueueDownload(url, headers).get();
|
auto [meta, content] = getFileTransfer()->download(url, headers);
|
||||||
|
res = std::move(meta);
|
||||||
|
data = content->drain();
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
if (cached) {
|
if (cached) {
|
||||||
warn("%s; using cached version", e.msg());
|
warn("%s; using cached version", e.msg());
|
||||||
|
|
|
@ -700,12 +700,6 @@ struct curlFileTransfer : public FileTransfer
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::future<std::pair<FileTransferResult, std::string>>
|
|
||||||
enqueueDownload(const std::string & uri, const Headers & headers = {}) override
|
|
||||||
{
|
|
||||||
return enqueueFileTransfer(uri, headers, std::nullopt, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
void upload(const std::string & uri, std::string data, const Headers & headers) override
|
void upload(const std::string & uri, std::string data, const Headers & headers) override
|
||||||
{
|
{
|
||||||
enqueueFileTransfer(uri, headers, std::move(data), false).get();
|
enqueueFileTransfer(uri, headers, std::move(data), false).get();
|
||||||
|
|
|
@ -69,13 +69,6 @@ struct FileTransfer
|
||||||
{
|
{
|
||||||
virtual ~FileTransfer() { }
|
virtual ~FileTransfer() { }
|
||||||
|
|
||||||
/**
|
|
||||||
* Enqueues a download request, returning a future for the result of
|
|
||||||
* the download. The future may throw a FileTransferError exception.
|
|
||||||
*/
|
|
||||||
virtual std::future<std::pair<FileTransferResult, std::string>>
|
|
||||||
enqueueDownload(const std::string & uri, const Headers & headers = {}) = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload some data. May throw a FileTransferError exception.
|
* Upload some data. May throw a FileTransferError exception.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -161,7 +161,7 @@ protected:
|
||||||
checkEnabled();
|
checkEnabled();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return std::move(getFileTransfer()->enqueueDownload(makeURI(path)).get().second);
|
return getFileTransfer()->download(makeURI(path)).second->drain();
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
|
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
|
||||||
return {};
|
return {};
|
||||||
|
|
|
@ -285,7 +285,8 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
|
||||||
Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
|
Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
|
||||||
|
|
||||||
// FIXME: use nixos.org?
|
// FIXME: use nixos.org?
|
||||||
auto [res, data] = getFileTransfer()->enqueueDownload(storePathsUrl).get();
|
auto [res, content] = getFileTransfer()->download(storePathsUrl);
|
||||||
|
auto data = content->drain();
|
||||||
|
|
||||||
auto state = std::make_unique<EvalState>(SearchPath{}, store);
|
auto state = std::make_unique<EvalState>(SearchPath{}, store);
|
||||||
auto v = state->allocValue();
|
auto v = state->allocValue();
|
||||||
|
|
|
@ -163,7 +163,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors))
|
||||||
auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; });
|
auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; });
|
||||||
auto ft = makeFileTransfer();
|
auto ft = makeFileTransfer();
|
||||||
ASSERT_THROW(
|
ASSERT_THROW(
|
||||||
ft->enqueueDownload(fmt("http://[::1]:%d/index", port)).get(),
|
ft->download(fmt("http://[::1]:%d/index", port)),
|
||||||
FileTransferError
|
FileTransferError
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ TEST(FileTransfer, usesIntermediateLinkHeaders)
|
||||||
{"200 ok", "content-length: 1\r\n", [] { return "a"; }},
|
{"200 ok", "content-length: 1\r\n", [] { return "a"; }},
|
||||||
});
|
});
|
||||||
auto ft = makeFileTransfer(0);
|
auto ft = makeFileTransfer(0);
|
||||||
auto [result, _data] = ft->enqueueDownload(fmt("http://[::1]:%d/first", port)).get();
|
auto [result, _data] = ft->download(fmt("http://[::1]:%d/first", port));
|
||||||
ASSERT_EQ(result.immutableUrl, "http://foo");
|
ASSERT_EQ(result.immutableUrl, "http://foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue