forked from lix-project/lix
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;
|
||||
std::string data;
|
||||
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) {
|
||||
if (cached) {
|
||||
warn("%s; using cached version", e.msg());
|
||||
|
|
|
@ -700,12 +700,6 @@ struct curlFileTransfer : public FileTransfer
|
|||
}
|
||||
#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
|
||||
{
|
||||
enqueueFileTransfer(uri, headers, std::move(data), false).get();
|
||||
|
|
|
@ -69,13 +69,6 @@ struct 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.
|
||||
*/
|
||||
|
|
|
@ -161,7 +161,7 @@ protected:
|
|||
checkEnabled();
|
||||
|
||||
try {
|
||||
return std::move(getFileTransfer()->enqueueDownload(makeURI(path)).get().second);
|
||||
return getFileTransfer()->download(makeURI(path)).second->drain();
|
||||
} catch (FileTransferError & e) {
|
||||
if (e.error == FileTransfer::NotFound || e.error == FileTransfer::Forbidden)
|
||||
return {};
|
||||
|
|
|
@ -285,7 +285,8 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
|
|||
Activity act(*logger, lvlInfo, actUnknown, "querying latest Nix version");
|
||||
|
||||
// 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 v = state->allocValue();
|
||||
|
|
|
@ -163,7 +163,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors))
|
|||
auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; });
|
||||
auto ft = makeFileTransfer();
|
||||
ASSERT_THROW(
|
||||
ft->enqueueDownload(fmt("http://[::1]:%d/index", port)).get(),
|
||||
ft->download(fmt("http://[::1]:%d/index", port)),
|
||||
FileTransferError
|
||||
);
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ TEST(FileTransfer, usesIntermediateLinkHeaders)
|
|||
{"200 ok", "content-length: 1\r\n", [] { return "a"; }},
|
||||
});
|
||||
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");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue