From fb852287551843e772c8bbe515ac9a32e742b000 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Sat, 9 Nov 2024 01:17:28 +0100 Subject: [PATCH] libstore: extract eager transfers into new method we'll need this shared code for kjified transfers that don't use sources. it's a while out, but we can clean this up now already. Change-Id: Ife8c160e6ab379761362d6c54aba05093deee99e --- src/libstore/filetransfer.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 8d7ccae87..88bcb3736 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -720,10 +720,10 @@ struct curlFileTransfer : public FileTransfer enqueueFileTransfer(uri, headers, std::move(data), false); } - std::pair> enqueueFileTransfer( + std::optional>> tryEagerTransfers( const std::string & uri, const Headers & headers, - std::optional data, + const std::optional & data, bool noBody ) { @@ -767,14 +767,14 @@ struct curlFileTransfer : public FileTransfer ); } if (S_ISDIR(st.st_mode)) { - return {std::move(metadata), make_box_ptr("")}; + return {{std::move(metadata), make_box_ptr("")}}; } struct OwningFdSource : FdSource { AutoCloseFD fd; OwningFdSource(AutoCloseFD fd) : FdSource(fd.get()), fd(std::move(fd)) {} }; - return {std::move(metadata), make_box_ptr(std::move(fd))}; + return {{std::move(metadata), make_box_ptr(std::move(fd))}}; } } @@ -796,7 +796,7 @@ struct curlFileTransfer : public FileTransfer FileTransferResult res; if (!s3Res.data) throw FileTransferError(NotFound, "S3 object '%s' does not exist", uri); - return {res, make_box_ptr(std::move(*s3Res.data))}; + return {{res, make_box_ptr(std::move(*s3Res.data))}}; #else throw nix::Error( "cannot download '%s' because Lix is not built with S3 support", uri @@ -804,6 +804,20 @@ struct curlFileTransfer : public FileTransfer #endif } + return std::nullopt; + } + + std::pair> enqueueFileTransfer( + const std::string & uri, + const Headers & headers, + std::optional data, + bool noBody + ) + { + if (auto eager = tryEagerTransfers(uri, headers, data, noBody)) { + return std::move(*eager); + } + struct State { bool done = false, failed = false; std::exception_ptr exc;