From 56e27e318401e1133556dbc1136be524c87932fe Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Thu, 24 Oct 2024 14:41:45 -0500 Subject: [PATCH] fix --- .../src/comm/curl/requests/http_put_file.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/repertory/librepertory/src/comm/curl/requests/http_put_file.cpp b/repertory/librepertory/src/comm/curl/requests/http_put_file.cpp index 09f2f8a5..ed1a5d6d 100644 --- a/repertory/librepertory/src/comm/curl/requests/http_put_file.cpp +++ b/repertory/librepertory/src/comm/curl/requests/http_put_file.cpp @@ -24,17 +24,18 @@ #include "utils/string.hpp" namespace repertory::curl::requests { -auto http_put_file::set_method(CURL *curl, - stop_type &stop_requested) const -> bool { +auto http_put_file::set_method(CURL *curl, stop_type &stop_requested) const + -> bool { curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT"); - curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); if (source_path.empty()) { - curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, 0L); + curl_easy_setopt(curl, CURLOPT_INFILE, nullptr); + curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0L); return true; } if (reader) { + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl, CURLOPT_READDATA, reader.get()); curl_easy_setopt( curl, CURLOPT_READFUNCTION, @@ -49,16 +50,23 @@ auto http_put_file::set_method(CURL *curl, utils::file::file::open_or_create_file(source_path), }); - if (not *read_info->file) { + if (not*read_info->file) { return false; } auto file_size = read_info->file->size(); + if (file_size > 0U) { + curl_easy_setopt(curl, CURLOPT_INFILE, nullptr); + curl_easy_setopt(curl, CURLOPT_INFILESIZE, 0L); + return true; + } + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt(curl, CURLOPT_READDATA, read_info.get()); curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_file_data); curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, file_size); +} - return true; +return true; } } // namespace repertory::curl::requests