From 2d49efaa2e9be53c657aed4ebc5eba450dde3d3d Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 26 Oct 2024 15:19:57 +0200 Subject: [PATCH] libstore: remove Filetransfer::transfer just use enqueueFileTransfer().get() insteaad. Change-Id: I67a43c9d3d5f68ac3f9e8ba7973c243dd78b86a3 --- src/libfetchers/tarball.cc | 2 +- src/libstore/filetransfer.cc | 5 ----- src/libstore/filetransfer.hh | 5 ----- src/libstore/http-binary-cache-store.cc | 4 ++-- src/nix/upgrade-nix.cc | 2 +- tests/unit/libstore/filetransfer.cc | 7 ++++--- 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 4c30193e2..11b205383 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -46,7 +46,7 @@ DownloadFileResult downloadFile( request.expectedETag = getStrAttr(cached->infoAttrs, "etag"); FileTransferResult res; try { - res = getFileTransfer()->transfer(request); + res = getFileTransfer()->enqueueFileTransfer(request).get(); } catch (FileTransferError & e) { if (cached) { warn("%s; using cached version", e.msg()); diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index c086911b0..95254a78a 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -868,11 +868,6 @@ ref makeFileTransfer() return makeCurlFileTransfer(); } -FileTransferResult FileTransfer::transfer(const FileTransferRequest & request) -{ - return enqueueFileTransfer(request).get(); -} - template FileTransferError::FileTransferError(FileTransfer::Error error, std::optional response, const Args & ... args) : Error(args...), error(error), response(response) diff --git a/src/libstore/filetransfer.hh b/src/libstore/filetransfer.hh index db441d6ef..4865fb59b 100644 --- a/src/libstore/filetransfer.hh +++ b/src/libstore/filetransfer.hh @@ -94,11 +94,6 @@ struct FileTransfer */ virtual std::future 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 * before the transfer has fully started, ensuring that any errors thrown by diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc index ea75768bd..36049b325 100644 --- a/src/libstore/http-binary-cache-store.cc +++ b/src/libstore/http-binary-cache-store.cc @@ -116,7 +116,7 @@ protected: try { FileTransferRequest request{makeURI(path)}; request.head = true; - getFileTransfer()->transfer(request); + getFileTransfer()->enqueueFileTransfer(request).get(); return true; } catch (FileTransferError & e) { /* S3 buckets return 403 if a file doesn't exist and the @@ -136,7 +136,7 @@ protected: req.data = StreamToSourceAdapter(istream).drain(); req.headers = {{"Content-Type", mimeType}}; try { - getFileTransfer()->transfer(req); + getFileTransfer()->enqueueFileTransfer(req).get(); } catch (FileTransferError & e) { throw UploadToHTTP("while uploading to HTTP binary cache at '%s': %s", cacheUri, e.msg()); } diff --git a/src/nix/upgrade-nix.cc b/src/nix/upgrade-nix.cc index 19f598874..791cdab64 100644 --- a/src/nix/upgrade-nix.cc +++ b/src/nix/upgrade-nix.cc @@ -286,7 +286,7 @@ struct CmdUpgradeNix : MixDryRun, EvalCommand // FIXME: use nixos.org? auto req = FileTransferRequest(storePathsUrl); - auto res = getFileTransfer()->transfer(req); + auto res = getFileTransfer()->enqueueFileTransfer(req).get(); auto state = std::make_unique(SearchPath{}, store); auto v = state->allocValue(); diff --git a/tests/unit/libstore/filetransfer.cc b/tests/unit/libstore/filetransfer.cc index fd4d326f0..1d8d0d5d7 100644 --- a/tests/unit/libstore/filetransfer.cc +++ b/tests/unit/libstore/filetransfer.cc @@ -163,8 +163,9 @@ TEST(FileTransfer, NOT_ON_DARWIN(reportsSetupErrors)) auto [port, srv] = serveHTTP("404 not found", "", [] { return ""; }); auto ft = makeFileTransfer(); ASSERT_THROW( - ft->transfer(FileTransferRequest(fmt("http://[::1]:%d/index", port))), - FileTransferError); + ft->enqueueFileTransfer(FileTransferRequest(fmt("http://[::1]:%d/index", port))).get(), + FileTransferError + ); } TEST(FileTransfer, NOT_ON_DARWIN(defersFailures)) @@ -218,7 +219,7 @@ TEST(FileTransfer, usesIntermediateLinkHeaders) auto ft = makeFileTransfer(); FileTransferRequest req(fmt("http://[::1]:%d/first", port)); req.baseRetryTimeMs = 0; - auto result = ft->transfer(req); + auto result = ft->enqueueFileTransfer(req).get(); ASSERT_EQ(result.immutableUrl, "http://foo"); }