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
This commit is contained in:
parent
3b1298efce
commit
3dba1d341a
|
@ -55,14 +55,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
std::unique_ptr<FILE, decltype([](FILE * f) { fclose(f); })> uploadData;
|
std::unique_ptr<FILE, decltype([](FILE * f) { fclose(f); })> uploadData;
|
||||||
Sync<DownloadState> downloadState;
|
Sync<DownloadState> downloadState;
|
||||||
std::condition_variable downloadEvent;
|
std::condition_variable downloadEvent;
|
||||||
enum {
|
bool headersDone = false;
|
||||||
/// nothing has been transferred yet
|
|
||||||
initialSetup,
|
|
||||||
/// data transfer in progress
|
|
||||||
transferring,
|
|
||||||
/// transfer complete, result or failure reported
|
|
||||||
transferComplete,
|
|
||||||
} phase = initialSetup;
|
|
||||||
std::promise<FileTransferResult> metadataPromise;
|
std::promise<FileTransferResult> metadataPromise;
|
||||||
std::string statusMsg;
|
std::string statusMsg;
|
||||||
|
|
||||||
|
@ -192,12 +185,12 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
void failEx(std::exception_ptr ex)
|
void failEx(std::exception_ptr ex)
|
||||||
{
|
{
|
||||||
assert(phase != transferComplete);
|
auto state = downloadState.lock();
|
||||||
if (phase == initialSetup) {
|
assert(!state->done && !state->exc);
|
||||||
|
if (!headersDone) {
|
||||||
metadataPromise.set_exception(ex);
|
metadataPromise.set_exception(ex);
|
||||||
}
|
}
|
||||||
phase = transferComplete;
|
state->exc = ex;
|
||||||
downloadState.lock()->exc = ex;
|
|
||||||
downloadEvent.notify_all();
|
downloadEvent.notify_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +202,7 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
void maybeFinishSetup()
|
void maybeFinishSetup()
|
||||||
{
|
{
|
||||||
if (phase > initialSetup) {
|
if (headersDone) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,10 +214,8 @@ struct curlFileTransfer : public FileTransfer
|
||||||
|
|
||||||
result.cached = getHTTPStatus() == 304;
|
result.cached = getHTTPStatus() == 304;
|
||||||
|
|
||||||
if (phase == initialSetup) {
|
|
||||||
metadataPromise.set_value(result);
|
metadataPromise.set_value(result);
|
||||||
}
|
headersDone = true;
|
||||||
phase = transferring;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::exception_ptr callbackException;
|
std::exception_ptr callbackException;
|
||||||
|
@ -338,7 +329,6 @@ struct curlFileTransfer : public FileTransfer
|
||||||
else if (code == CURLE_OK && successfulStatuses.count(httpStatus))
|
else if (code == CURLE_OK && successfulStatuses.count(httpStatus))
|
||||||
{
|
{
|
||||||
act.progress(bodySize, bodySize);
|
act.progress(bodySize, bodySize);
|
||||||
phase = transferComplete;
|
|
||||||
downloadState.lock()->done = true;
|
downloadState.lock()->done = true;
|
||||||
downloadEvent.notify_all();
|
downloadEvent.notify_all();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue