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;