Skip to content

Commit

Permalink
Fixed ETag parsing at completing the Multipart upload part
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Oct 7, 2023
1 parent d0c4b5c commit 2e03f5e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
11 changes: 4 additions & 7 deletions src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4218,6 +4218,7 @@ bool S3fsCurl::UploadMultipartPostComplete()
if (it == responseHeaders.end()) {
return false;
}
std::string etag = trim(it->second, "\"");

// check etag(md5);
//
Expand All @@ -4227,11 +4228,11 @@ bool S3fsCurl::UploadMultipartPostComplete()
// https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingKMSEncryption.html
//
if(S3fsCurl::is_content_md5 && sse_type_t::SSE_C != S3fsCurl::GetSseType() && sse_type_t::SSE_KMS != S3fsCurl::GetSseType()){
if(!etag_equals(it->second, partdata.etag)){
if(!etag_equals(etag, partdata.etag)){
return false;
}
}
partdata.petag->etag = it->second;
partdata.petag->etag = etag;
partdata.uploaded = true;

return true;
Expand All @@ -4255,11 +4256,7 @@ bool S3fsCurl::CopyMultipartPostComplete()
{
std::string etag;
partdata.uploaded = simple_parse_xml(bodydata.c_str(), bodydata.size(), "ETag", etag);
if(etag.size() >= 2 && *etag.begin() == '"' && *etag.rbegin() == '"'){
etag.erase(etag.size() - 1);
etag.erase(0, 1);
}
partdata.petag->etag = etag;
partdata.petag->etag = trim(etag, "\"");

bodydata.clear();
headdata.clear();
Expand Down
12 changes: 2 additions & 10 deletions src/curl_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,9 @@ const char* getCurlDebugHead(curl_infotype type)
//
// compare ETag ignoring quotes and case
//
bool etag_equals(std::string s1, std::string s2)
bool etag_equals(const std::string& s1, const std::string& s2)
{
if(s1.length() > 1 && s1[0] == '\"' && *s1.rbegin() == '\"'){
s1.erase(s1.size() - 1);
s1.erase(0, 1);
}
if(s2.length() > 1 && s2[0] == '\"' && *s2.rbegin() == '\"'){
s2.erase(s2.size() - 1);
s2.erase(0, 1);
}
return 0 == strcasecmp(s1.c_str(), s2.c_str());
return 0 == strcasecmp(trim(s1, "\"").c_str(), trim(s2, "\"").c_str());
}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/curl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ std::string url_to_host(const std::string &url);
std::string get_bucket_host();
const char* getCurlDebugHead(curl_infotype type);

bool etag_equals(std::string s1, std::string s2);
bool etag_equals(const std::string& s1, const std::string& s2);

#endif // S3FS_CURL_UTIL_H_

Expand Down

0 comments on commit 2e03f5e

Please sign in to comment.