From bd5c29d76bbcb1d45210ba3689b08e457e718317 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 25 Apr 2024 01:27:29 +0200 Subject: [PATCH] filetransfer: drop errorSink just accumulate error data into result.data as we would for successful transfers without a dataCallback. errorSink and data would contain the same data in error cases anyway, so splitting them is not very useful. Change-Id: I00e449866454389ac6a564ab411c903fd357dabf --- src/libstore/filetransfer.cc | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index aa4a6d453..9dc742220 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -90,19 +90,12 @@ struct curlFileTransfer : public FileTransfer {request.uri}, request.parentAct) , callback(std::move(callback)) , finalSink([this](std::string_view data) { - if (errorSink) { - (*errorSink)(data); - } - - if (this->request.dataCallback) { - auto httpStatus = getHTTPStatus(); - + auto httpStatus = getHTTPStatus(); /* Only write data to the sink if this is a successful response. */ - if (successfulStatuses.count(httpStatus)) { - writtenToSink += data.size(); - this->request.dataCallback(data); - } + if (successfulStatuses.count(httpStatus) && this->request.dataCallback) { + writtenToSink += data.size(); + this->request.dataCallback(data); } else this->result.data.append(data); }) @@ -148,7 +141,6 @@ struct curlFileTransfer : public FileTransfer LambdaSink finalSink; std::shared_ptr decompressionSink; - std::optional errorSink; std::exception_ptr writeException; @@ -184,13 +176,6 @@ struct curlFileTransfer : public FileTransfer if (!decompressionSink) { decompressionSink = makeDecompressionSink(encoding, finalSink); - if (! successfulStatuses.count(getHTTPStatus())) { - // In this case we want to construct a TeeSink, to keep - // the response around (which we figure won't be big - // like an actual download should be) to improve error - // messages. - errorSink = StringSink { }; - } } (*decompressionSink)({(char *) contents, realSize}); @@ -448,8 +433,8 @@ struct curlFileTransfer : public FileTransfer attempt++; std::optional response; - if (errorSink) - response = std::move(errorSink->s); + if (!successfulStatuses.count(httpStatus)) + response = std::move(result.data); auto exc = code == CURLE_ABORTED_BY_CALLBACK && _isInterrupted ? FileTransferError(Interrupted, std::move(response), "%s of '%s' was interrupted", request.verb(), request.uri)