filetransfer: {up,down}load -> transfer
even the transfer function is not all that necessary since there aren't
that many users, but we'll keep it for now. we could've kept both names
but we also kind of want to use `download` for something else very soon
Change-Id: I005e403ee59de433e139e37aa2045c26a523ccbf
This commit is contained in:
parent
b9b1bbd22f
commit
0b9a72524a
|
@ -46,7 +46,7 @@ DownloadFileResult downloadFile(
|
||||||
request.expectedETag = getStrAttr(cached->infoAttrs, "etag");
|
request.expectedETag = getStrAttr(cached->infoAttrs, "etag");
|
||||||
FileTransferResult res;
|
FileTransferResult res;
|
||||||
try {
|
try {
|
||||||
res = getFileTransfer()->download(request);
|
res = getFileTransfer()->transfer(request);
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
if (cached) {
|
if (cached) {
|
||||||
warn("%s; using cached version", e.msg());
|
warn("%s; using cached version", e.msg());
|
||||||
|
|
|
@ -817,17 +817,11 @@ ref<FileTransfer> makeFileTransfer()
|
||||||
return makeCurlFileTransfer();
|
return makeCurlFileTransfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTransferResult FileTransfer::download(const FileTransferRequest & request)
|
FileTransferResult FileTransfer::transfer(const FileTransferRequest & request)
|
||||||
{
|
{
|
||||||
return enqueueFileTransfer(request).get();
|
return enqueueFileTransfer(request).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTransferResult FileTransfer::upload(const FileTransferRequest & request)
|
|
||||||
{
|
|
||||||
/* Note: this method is the same as download, but helps in readability */
|
|
||||||
return enqueueFileTransfer(request).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
FileTransferError::FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args)
|
FileTransferError::FileTransferError(FileTransfer::Error error, std::optional<std::string> response, const Args & ... args)
|
||||||
: Error(args...), error(error), response(response)
|
: Error(args...), error(error), response(response)
|
||||||
|
|
|
@ -99,14 +99,9 @@ struct FileTransfer
|
||||||
virtual std::future<FileTransferResult> enqueueFileTransfer(const FileTransferRequest & request) = 0;
|
virtual std::future<FileTransferResult> enqueueFileTransfer(const FileTransferRequest & request) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synchronously download a file.
|
* Synchronously transfer a file.
|
||||||
*/
|
*/
|
||||||
FileTransferResult download(const FileTransferRequest & request);
|
FileTransferResult transfer(const FileTransferRequest & request);
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously upload a file.
|
|
||||||
*/
|
|
||||||
FileTransferResult upload(const FileTransferRequest & 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
|
||||||
|
|
|
@ -115,7 +115,7 @@ protected:
|
||||||
try {
|
try {
|
||||||
FileTransferRequest request(makeRequest(path));
|
FileTransferRequest request(makeRequest(path));
|
||||||
request.head = true;
|
request.head = true;
|
||||||
getFileTransfer()->download(request);
|
getFileTransfer()->transfer(request);
|
||||||
return true;
|
return true;
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
/* S3 buckets return 403 if a file doesn't exist and the
|
/* S3 buckets return 403 if a file doesn't exist and the
|
||||||
|
@ -135,7 +135,7 @@ protected:
|
||||||
req.data = StreamToSourceAdapter(istream).drain();
|
req.data = StreamToSourceAdapter(istream).drain();
|
||||||
req.mimeType = mimeType;
|
req.mimeType = mimeType;
|
||||||
try {
|
try {
|
||||||
getFileTransfer()->upload(req);
|
getFileTransfer()->transfer(req);
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg());
|
throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg());
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand
|
||||||
|
|
||||||
// FIXME: use nixos.org?
|
// FIXME: use nixos.org?
|
||||||
auto req = FileTransferRequest(storePathsUrl);
|
auto req = FileTransferRequest(storePathsUrl);
|
||||||
auto res = getFileTransfer()->download(req);
|
auto res = getFileTransfer()->transfer(req);
|
||||||
|
|
||||||
auto state = std::make_unique<EvalState>(SearchPath{}, store);
|
auto state = std::make_unique<EvalState>(SearchPath{}, store);
|
||||||
auto v = state->allocValue();
|
auto v = state->allocValue();
|
||||||
|
|
|
@ -155,7 +155,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->download(FileTransferRequest(fmt("http://[::1]:%d/index", port))),
|
ft->transfer(FileTransferRequest(fmt("http://[::1]:%d/index", port))),
|
||||||
FileTransferError);
|
FileTransferError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsTransferError))
|
||||||
auto ft = makeFileTransfer();
|
auto ft = makeFileTransfer();
|
||||||
FileTransferRequest req(fmt("http://[::1]:%d/index", port));
|
FileTransferRequest req(fmt("http://[::1]:%d/index", port));
|
||||||
req.baseRetryTimeMs = 0;
|
req.baseRetryTimeMs = 0;
|
||||||
ASSERT_THROW(ft->download(req), FileTransferError);
|
ASSERT_THROW(ft->transfer(req), FileTransferError);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FileTransfer, NOT_ON_DARWIN(handlesContentEncoding))
|
TEST(FileTransfer, NOT_ON_DARWIN(handlesContentEncoding))
|
||||||
|
@ -205,7 +205,7 @@ TEST(FileTransfer, usesIntermediateLinkHeaders)
|
||||||
auto ft = makeFileTransfer();
|
auto ft = makeFileTransfer();
|
||||||
FileTransferRequest req(fmt("http://[::1]:%d/first", port));
|
FileTransferRequest req(fmt("http://[::1]:%d/first", port));
|
||||||
req.baseRetryTimeMs = 0;
|
req.baseRetryTimeMs = 0;
|
||||||
auto result = ft->download(req);
|
auto result = ft->transfer(req);
|
||||||
ASSERT_EQ(result.immutableUrl, "http://foo");
|
ASSERT_EQ(result.immutableUrl, "http://foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue