From 85ca2a3e455c6bc57ee1132b7f3bb4011fbb77d0 Mon Sep 17 00:00:00 2001 From: LiuBingrun <610253799@qq.com> Date: Sat, 27 Nov 2021 15:53:26 +0800 Subject: [PATCH] fix mixupload return EntityTooSmall while a copypart is less than 5MB after split (#1809) * fix mixupload return EntityTooSmall while a copypart is less than 5MB after split * fix possible part exceeds 5GB when multipart_copy_size is set to 5120MB * Update curl.cpp Co-authored-by: liubingrun --- src/curl.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index a2113f7..2b590ee 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -1453,10 +1453,21 @@ int S3fsCurl::ParallelMixMultipartUploadRequest(const char* tpath, headers_t& me } }else{ // Multipart copy - for(off_t i = 0; i < iter->bytes; i += GetMultipartCopySize()){ + for(off_t i = 0, bytes = 0; i < iter->bytes; i += bytes){ S3fsCurl* s3fscurl_para = new S3fsCurl(true); - off_t bytes = std::min(static_cast(GetMultipartCopySize()), iter->bytes - i); + bytes = std::min(static_cast(GetMultipartCopySize()), iter->bytes - i); + /* every part should be larger than MIN_MULTIPART_SIZE and smaller than FIVE_GB */ + off_t remain_bytes = iter->bytes - i - bytes; + + if ((MIN_MULTIPART_SIZE > remain_bytes) && (0 < remain_bytes)){ + if(FIVE_GB < (bytes + remain_bytes)){ + bytes = (bytes + remain_bytes)/2; + } else{ + bytes += remain_bytes; + } + } + std::ostringstream strrange; strrange << "bytes=" << (iter->offset + i) << "-" << (iter->offset + i + bytes - 1); meta["x-amz-copy-source-range"] = strrange.str();