diff options
author | eldritch horrors <pennae@lix.systems> | 2024-04-25 01:27:29 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-04-25 01:33:22 +0200 |
commit | 5420b3afd6c328faf1508dce03bbe8e58da8af2b (patch) | |
tree | b2509f1d433029661b22b3b209fd01d67d3eb586 /src/libstore/filetransfer.cc | |
parent | 5e69f8aa3d5447e348f753f23748e4fe66306b6d (diff) |
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
Diffstat (limited to 'src/libstore/filetransfer.cc')
-rw-r--r-- | src/libstore/filetransfer.cc | 27 |
1 files 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<FinishSink> decompressionSink; - std::optional<StringSink> 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<std::string> 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) |