libstore: remove Filetransfer::transfer
just use enqueueFileTransfer().get() insteaad.
Change-Id: I67a43c9d3d5f68ac3f9e8ba7973c243dd78b86a3
This commit is contained in:
parent
98b55c3a1d
commit
2d49efaa2e
|
@ -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()->transfer(request);
|
res = getFileTransfer()->enqueueFileTransfer(request).get();
|
||||||
} catch (FileTransferError & e) {
|
} catch (FileTransferError & e) {
|
||||||
if (cached) {
|
if (cached) {
|
||||||
warn("%s; using cached version", e.msg());
|
warn("%s; using cached version", e.msg());
|
||||||
|
|
|
@ -868,11 +868,6 @@ ref<FileTransfer> makeFileTransfer()
|
||||||
return makeCurlFileTransfer();
|
return makeCurlFileTransfer();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTransferResult FileTransfer::transfer(const FileTransferRequest & request)
|
|
||||||
{
|
|
||||||
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)
|
||||||
|
|
|
@ -94,11 +94,6 @@ struct FileTransfer
|
||||||
*/
|
*/
|
||||||
virtual std::future<FileTransferResult> enqueueFileTransfer(const FileTransferRequest & request) = 0;
|
virtual std::future<FileTransferResult> enqueueFileTransfer(const FileTransferRequest & request) = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Synchronously transfer a file.
|
|
||||||
*/
|
|
||||||
FileTransferResult transfer(const FileTransferRequest & request);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file, returning its contents through a source. Will not return
|
* Download a file, returning its contents through a source. Will not return
|
||||||
* before the transfer has fully started, ensuring that any errors thrown by
|
* before the transfer has fully started, ensuring that any errors thrown by
|
||||||
|
|
|
@ -116,7 +116,7 @@ protected:
|
||||||
try {
|
try {
|
||||||
FileTransferRequest request{makeURI(path)};
|
FileTransferRequest request{makeURI(path)};
|
||||||
request.head = true;
|
request.head = true;
|
||||||
getFileTransfer()->transfer(request);
|
getFileTransfer()->enqueueFileTransfer(request).get();
|
||||||
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
|
||||||
|
@ -136,7 +136,7 @@ protected:
|
||||||
req.data = StreamToSourceAdapter(istream).drain();
|
req.data = StreamToSourceAdapter(istream).drain();
|
||||||
req.headers = {{"Content-Type", mimeType}};
|
req.headers = {{"Content-Type", mimeType}};
|
||||||
try {
|
try {
|
||||||
getFileTransfer()->transfer(req);
|
getFileTransfer()->enqueueFileTransfer(req).get();
|
||||||
} 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()->transfer(req);
|
auto res = getFileTransfer()->enqueueFileTransfer(req).get();
|
||||||
|
|
||||||
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,8 +163,9 @@ 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->transfer(FileTransferRequest(fmt("http://[::1]:%d/index", port))),
|
ft->enqueueFileTransfer(FileTransferRequest(fmt("http://[::1]:%d/index", port))).get(),
|
||||||
FileTransferError);
|
FileTransferError
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FileTransfer, NOT_ON_DARWIN(defersFailures))
|
TEST(FileTransfer, NOT_ON_DARWIN(defersFailures))
|
||||||
|
@ -218,7 +219,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->transfer(req);
|
auto result = ft->enqueueFileTransfer(req).get();
|
||||||
ASSERT_EQ(result.immutableUrl, "http://foo");
|
ASSERT_EQ(result.immutableUrl, "http://foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue