diff --git a/examples/GetObjectProgress.cc b/examples/GetObjectProgress.cc index 729787e..5d089dd 100644 --- a/examples/GetObjectProgress.cc +++ b/examples/GetObjectProgress.cc @@ -37,7 +37,7 @@ int main() { << std::endl; return true; }; - args.progressfunc = [](minio::http::ProgressFunctionArgs args) -> void { + args.progressfunc = [](minio::http::ProgressFunctionArgs args) -> bool { if (args.download_speed > 0) { std::cout << "downloaded speed: " << (long)args.download_speed << " bps" << std::endl; @@ -45,6 +45,7 @@ int main() { std::cout << "downloaded: " << (long)args.downloaded_bytes << " bytes of " << (long)args.download_total_bytes << " bytes" << std::endl; } + return true; }; // Call get object. diff --git a/examples/PutObjectProgress.cc b/examples/PutObjectProgress.cc index db107ad..a9631aa 100644 --- a/examples/PutObjectProgress.cc +++ b/examples/PutObjectProgress.cc @@ -43,7 +43,7 @@ int main() { minio::s3::PutObjectArgs args(file, 47615315, 15728640); args.bucket = "my-bucket"; args.object = "my-object"; - args.progressfunc = [](minio::http::ProgressFunctionArgs args) -> void { + args.progressfunc = [](minio::http::ProgressFunctionArgs args) -> bool { if (args.upload_speed > 0) { std::cout << "uploaded speed: " << (long)args.upload_speed << " bps" << std::endl; @@ -51,6 +51,7 @@ int main() { std::cout << "uploaded: " << (long)args.uploaded_bytes << " bytes of " << (long)args.upload_total_bytes << " bytes" << std::endl; } + return true; }; // Call put object. diff --git a/include/miniocpp/http.h b/include/miniocpp/http.h index 2ead3b3..a3754a3 100644 --- a/include/miniocpp/http.h +++ b/include/miniocpp/http.h @@ -69,7 +69,7 @@ using DataFunction = std::function; struct ProgressFunctionArgs; -using ProgressFunction = std::function; +using ProgressFunction = std::function; struct Response; diff --git a/src/client.cc b/src/client.cc index 6d47cf5..5673315 100644 --- a/src/client.cc +++ b/src/client.cc @@ -484,21 +484,21 @@ PutObjectResponse Client::PutObject(PutObjectArgs args, std::string& upload_id, [&object_size = object_size, &uploaded_bytes = uploaded_bytes, &upload_speed = upload_speed, &progressfunc = args.progressfunc, &progress_userdata = args.progress_userdata]( - http::ProgressFunctionArgs args) -> void { + http::ProgressFunctionArgs args) -> bool { if (args.upload_speed > 0) { if (upload_speed == -1) { upload_speed = args.upload_speed; } else { upload_speed = (upload_speed + args.upload_speed) / 2; } - return; + return true; } http::ProgressFunctionArgs actual_args; actual_args.upload_total_bytes = static_cast(object_size); actual_args.uploaded_bytes = uploaded_bytes + args.uploaded_bytes; actual_args.userdata = progress_userdata; - progressfunc(actual_args); + return progressfunc(actual_args); }; } if (args.sse != nullptr) { @@ -514,7 +514,10 @@ PutObjectResponse Client::PutObject(PutObjectArgs args, std::string& upload_id, actual_args.upload_total_bytes = static_cast(object_size); actual_args.uploaded_bytes = uploaded_bytes; actual_args.userdata = args.progress_userdata; - args.progressfunc(actual_args); + if (!args.progressfunc(actual_args)) { + return UploadPartResponse( + error::Error("aborted by progress function")); + } } parts.push_back(Part(part_number, std::move(resp.etag))); } else { @@ -533,6 +536,7 @@ PutObjectResponse Client::PutObject(PutObjectArgs args, std::string& upload_id, http::ProgressFunctionArgs actual_args; actual_args.upload_speed = upload_speed; actual_args.userdata = args.progress_userdata; + // ignore the return value as we completed the upload args.progressfunc(actual_args); } return PutObjectResponse(resp); @@ -792,6 +796,8 @@ UploadObjectResponse Client::UploadObject(UploadObjectArgs args) { po_args.retention = std::move(args.retention); po_args.legal_hold = std::move(args.legal_hold); po_args.content_type = std::move(args.content_type); + po_args.progressfunc = std::move(args.progressfunc); + po_args.progress_userdata = std::move(args.progress_userdata); PutObjectResponse resp = PutObject(std::move(po_args)); file.close(); diff --git a/src/http.cc b/src/http.cc index 4234346..8af3dfa 100644 --- a/src/http.cc +++ b/src/http.cc @@ -411,8 +411,10 @@ Response Request::execute() { args.upload_total_bytes = ultotal; args.uploaded_bytes = ulnow; args.userdata = progress_userdata; - progressfunc(args); - return CURL_PROGRESSFUNC_CONTINUE; + if (progressfunc(args)) { + return CURL_PROGRESSFUNC_CONTINUE; + } + return 1; }; if (progressfunc != nullptr) { request.setOpt(new curlpp::options::NoProgress(false));