From f75d0752ce8fa156feb92b2b31f4f3326f65476b Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 6 May 2024 16:46:11 +0200 Subject: [PATCH] filetransfer: correctly abort empty transfers returning 0 from the callback for errors signals successful transfer if the source returned no data even though the exception we've just caught clearly disagrees. while this is not all that important (since the only viable cause of such errors will be dataCallback, and the sole instance of it being used already takes care of exceptions) we can just do this. Change-Id: I2bb150eff447121d82e8e3aa4e00057c40523ac6 --- src/libstore/filetransfer.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index a0e3fd586..67b9fef81 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -149,6 +149,8 @@ struct curlFileTransfer : public FileTransfer size_t writeCallback(void * contents, size_t size, size_t nmemb) { + const size_t realSize = size * nmemb; + try { if (!headersProcessed) { if (auto h = getHeader("content-encoding")) { @@ -161,7 +163,6 @@ struct curlFileTransfer : public FileTransfer headersProcessed = true; } - size_t realSize = size * nmemb; result.bodySize += realSize; if (successfulStatuses.count(getHTTPStatus()) && this->dataCallback) { @@ -174,7 +175,7 @@ struct curlFileTransfer : public FileTransfer return realSize; } catch (...) { writeException = std::current_exception(); - return 0; + return CURL_WRITEFUNC_ERROR; } }