From 3dba1d341a31c4bd05da30463238e8ee9e726b4c Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 15 Nov 2024 16:15:11 +0100 Subject: [PATCH] libstore: remove TransferItem::phase transferComplete has outlived its usefulness, and the other two phases can be a boolean flag telling us whether we're still receiving headers Change-Id: Ia943f95dcf0ce8ee2cc6d0f44ddf13151aef4346 --- src/libstore/filetransfer.cc | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/libstore/filetransfer.cc b/src/libstore/filetransfer.cc index 75e3667fc..c29132d9c 100644 --- a/src/libstore/filetransfer.cc +++ b/src/libstore/filetransfer.cc @@ -55,14 +55,7 @@ struct curlFileTransfer : public FileTransfer std::unique_ptr uploadData; Sync downloadState; std::condition_variable downloadEvent; - enum { - /// nothing has been transferred yet - initialSetup, - /// data transfer in progress - transferring, - /// transfer complete, result or failure reported - transferComplete, - } phase = initialSetup; + bool headersDone = false; std::promise metadataPromise; std::string statusMsg; @@ -192,12 +185,12 @@ struct curlFileTransfer : public FileTransfer void failEx(std::exception_ptr ex) { - assert(phase != transferComplete); - if (phase == initialSetup) { + auto state = downloadState.lock(); + assert(!state->done && !state->exc); + if (!headersDone) { metadataPromise.set_exception(ex); } - phase = transferComplete; - downloadState.lock()->exc = ex; + state->exc = ex; downloadEvent.notify_all(); } @@ -209,7 +202,7 @@ struct curlFileTransfer : public FileTransfer void maybeFinishSetup() { - if (phase > initialSetup) { + if (headersDone) { return; } @@ -221,10 +214,8 @@ struct curlFileTransfer : public FileTransfer result.cached = getHTTPStatus() == 304; - if (phase == initialSetup) { - metadataPromise.set_value(result); - } - phase = transferring; + metadataPromise.set_value(result); + headersDone = true; } std::exception_ptr callbackException; @@ -338,7 +329,6 @@ struct curlFileTransfer : public FileTransfer else if (code == CURLE_OK && successfulStatuses.count(httpStatus)) { act.progress(bodySize, bodySize); - phase = transferComplete; downloadState.lock()->done = true; downloadEvent.notify_all(); }