Fixed ETag parsing at completing the Multipart upload part

This commit is contained in:
Takeshi Nakatani 2023-10-07 03:31:42 +00:00 committed by Andrew Gaul
parent e5b15bed7d
commit 5e5b4f0a49
6 changed files with 25 additions and 18 deletions

View File

@ -4218,6 +4218,7 @@ bool S3fsCurl::UploadMultipartPostComplete()
if (it == responseHeaders.end()) {
return false;
}
std::string etag = peeloff(it->second);
// check etag(md5);
//
@ -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;
@ -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 = peeloff(etag);
bodydata.clear();
headdata.clear();

View File

@ -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(peeloff(s1).c_str(), peeloff(s2).c_str());
}
/*

View File

@ -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_

View File

@ -125,6 +125,14 @@ std::string trim(std::string s, const char *t /* = SPACES */)
return trim_left(trim_right(std::move(s), t), t);
}
std::string peeloff(std::string s)
{
if(s.size() < 2 || *s.begin() != '"' || *s.rbegin() != '"'){
return s;
}
return s.substr(1, s.size() - 2);
}
//
// Three url encode functions
//

View File

@ -79,6 +79,7 @@ std::string trim_left(std::string s, const char *t = SPACES);
std::string trim_right(std::string s, const char *t = SPACES);
std::string trim(std::string s, const char *t = SPACES);
std::string lower(std::string s);
std::string peeloff(std::string s);
//
// Date string

View File

@ -49,6 +49,15 @@ void test_trim()
ASSERT_EQUALS(std::string("1234"), trim_right("1234 "));
ASSERT_EQUALS(std::string(" 1234"), trim_right(" 1234"));
ASSERT_EQUALS(std::string("1234"), trim_right("1234"));
ASSERT_EQUALS(std::string("1234"), peeloff("\"1234\"")); // "1234" -> 1234
ASSERT_EQUALS(std::string("\"1234\""), peeloff("\"\"1234\"\"")); // ""1234"" -> "1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"\"1234\"")); // ""1234" -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("\"1234\"\"")); // "1234"" -> 1234"
ASSERT_EQUALS(std::string("\"1234"), peeloff("\"1234")); // "1234 -> "1234
ASSERT_EQUALS(std::string("1234\""), peeloff("1234\"")); // 1234" -> 1234"
ASSERT_EQUALS(std::string(" \"1234\""), peeloff(" \"1234\"")); // _"1234" -> _"1234"
ASSERT_EQUALS(std::string("\"1234\" "), peeloff("\"1234\" ")); // "1234"_ -> "1234"_
}
void test_base64()