DownloadRequest -> DataTransferRequest

This commit is contained in:
Nikola Knezevic 2020-04-06 13:30:45 +02:00
parent 5449ff7d8a
commit 65ef57e0cb
6 changed files with 19 additions and 20 deletions

View file

@ -36,7 +36,7 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
/* No need to do TLS verification, because we check the hash of /* No need to do TLS verification, because we check the hash of
the result anyway. */ the result anyway. */
DownloadRequest request(url); DataTransferRequest request(url);
request.verifyTLS = false; request.verifyTLS = false;
request.decompress = false; request.decompress = false;

View file

@ -49,7 +49,7 @@ struct CurlDownloader : public Downloader
struct DownloadItem : public std::enable_shared_from_this<DownloadItem> struct DownloadItem : public std::enable_shared_from_this<DownloadItem>
{ {
CurlDownloader & downloader; CurlDownloader & downloader;
DownloadRequest request; DataTransferRequest request;
DownloadResult result; DownloadResult result;
Activity act; Activity act;
bool done = false; // whether either the success or failure function has been called bool done = false; // whether either the success or failure function has been called
@ -73,7 +73,7 @@ struct CurlDownloader : public Downloader
curl_off_t writtenToSink = 0; curl_off_t writtenToSink = 0;
DownloadItem(CurlDownloader & downloader, DownloadItem(CurlDownloader & downloader,
const DownloadRequest & request, const DataTransferRequest & request,
Callback<DownloadResult> && callback) Callback<DownloadResult> && callback)
: downloader(downloader) : downloader(downloader)
, request(request) , request(request)
@ -641,7 +641,7 @@ struct CurlDownloader : public Downloader
} }
#endif #endif
void enqueueDownload(const DownloadRequest & request, void enqueueDownload(const DataTransferRequest & request,
Callback<DownloadResult> callback) override Callback<DownloadResult> callback) override
{ {
/* Ugly hack to support s3:// URIs. */ /* Ugly hack to support s3:// URIs. */
@ -687,7 +687,7 @@ ref<Downloader> makeDownloader()
return make_ref<CurlDownloader>(); return make_ref<CurlDownloader>();
} }
std::future<DownloadResult> Downloader::enqueueDownload(const DownloadRequest & request) std::future<DownloadResult> Downloader::enqueueDownload(const DataTransferRequest & request)
{ {
auto promise = std::make_shared<std::promise<DownloadResult>>(); auto promise = std::make_shared<std::promise<DownloadResult>>();
enqueueDownload(request, enqueueDownload(request,
@ -701,12 +701,12 @@ std::future<DownloadResult> Downloader::enqueueDownload(const DownloadRequest &
return promise->get_future(); return promise->get_future();
} }
DownloadResult Downloader::download(const DownloadRequest & request) DownloadResult Downloader::download(const DataTransferRequest & request)
{ {
return enqueueDownload(request).get(); return enqueueDownload(request).get();
} }
void Downloader::download(DownloadRequest && request, Sink & sink) void Downloader::download(DataTransferRequest && request, Sink & sink)
{ {
/* Note: we can't call 'sink' via request.dataCallback, because /* Note: we can't call 'sink' via request.dataCallback, because
that would cause the sink to execute on the downloader that would cause the sink to execute on the downloader
@ -801,7 +801,6 @@ void Downloader::download(DownloadRequest && request, Sink & sink)
} }
} }
bool isUri(const string & s) bool isUri(const string & s)
{ {
if (s.compare(0, 8, "channel:") == 0) return true; if (s.compare(0, 8, "channel:") == 0) return true;

View file

@ -33,7 +33,7 @@ struct DownloadSettings : Config
extern DownloadSettings downloadSettings; extern DownloadSettings downloadSettings;
struct DownloadRequest struct DataTransferRequest
{ {
std::string uri; std::string uri;
std::string expectedETag; std::string expectedETag;
@ -47,7 +47,7 @@ struct DownloadRequest
std::string mimeType; std::string mimeType;
std::function<void(char *, size_t)> dataCallback; std::function<void(char *, size_t)> dataCallback;
DownloadRequest(const std::string & uri) DataTransferRequest(const std::string & uri)
: uri(uri), parentAct(getCurActivity()) { } : uri(uri), parentAct(getCurActivity()) { }
std::string verb() std::string verb()
@ -74,17 +74,17 @@ struct Downloader
/* Enqueue a download request, returning a future to the result of /* Enqueue a download request, returning a future to the result of
the download. The future may throw a DownloadError the download. The future may throw a DownloadError
exception. */ exception. */
virtual void enqueueDownload(const DownloadRequest & request, virtual void enqueueDownload(const DataTransferRequest & request,
Callback<DownloadResult> callback) = 0; Callback<DownloadResult> callback) = 0;
std::future<DownloadResult> enqueueDownload(const DownloadRequest & request); std::future<DownloadResult> enqueueDownload(const DataTransferRequest & request);
/* Synchronously download a file. */ /* Synchronously download a file. */
DownloadResult download(const DownloadRequest & request); DownloadResult download(const DataTransferRequest & request);
/* Download a file, writing its data to a sink. The sink will be /* Download a file, writing its data to a sink. The sink will be
invoked on the thread of the caller. */ invoked on the thread of the caller. */
void download(DownloadRequest && request, Sink & sink); void download(DataTransferRequest && request, Sink & sink);
enum Error { NotFound, Forbidden, Misc, Transient, Interrupted }; enum Error { NotFound, Forbidden, Misc, Transient, Interrupted };
}; };

View file

@ -85,7 +85,7 @@ protected:
checkEnabled(); checkEnabled();
try { try {
DownloadRequest request(cacheUri + "/" + path); DataTransferRequest request(cacheUri + "/" + path);
request.head = true; request.head = true;
getDownloader()->download(request); getDownloader()->download(request);
return true; return true;
@ -103,7 +103,7 @@ protected:
const std::string & data, const std::string & data,
const std::string & mimeType) override const std::string & mimeType) override
{ {
auto req = DownloadRequest(cacheUri + "/" + path); auto req = DataTransferRequest(cacheUri + "/" + path);
req.data = std::make_shared<string>(data); // FIXME: inefficient req.data = std::make_shared<string>(data); // FIXME: inefficient
req.mimeType = mimeType; req.mimeType = mimeType;
try { try {
@ -113,9 +113,9 @@ protected:
} }
} }
DownloadRequest makeRequest(const std::string & path) DataTransferRequest makeRequest(const std::string & path)
{ {
DownloadRequest request(cacheUri + "/" + path); DataTransferRequest request(cacheUri + "/" + path);
return request; return request;
} }

View file

@ -180,7 +180,7 @@ static int _main(int argc, char * * argv)
FdSink sink(fd.get()); FdSink sink(fd.get());
DownloadRequest req(actualUri); DataTransferRequest req(actualUri);
req.decompress = false; req.decompress = false;
getDownloader()->download(std::move(req), sink); getDownloader()->download(std::move(req), sink);
} }

View file

@ -138,7 +138,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
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 req = DownloadRequest(storePathsUrl); auto req = DataTransferRequest(storePathsUrl);
auto res = getDownloader()->download(req); auto res = getDownloader()->download(req);
auto state = std::make_unique<EvalState>(Strings(), store); auto state = std::make_unique<EvalState>(Strings(), store);