Skip to content

Commit

Permalink
Merge pull request s3fs-fuse#556 from orozery/fix_nocache_multipart_u…
Browse files Browse the repository at this point in the history
…pload

fix multipart upload handling without cache
  • Loading branch information
ggtakec authored Apr 16, 2017
2 parents edcf4c6 + ff3eb19 commit df0ff3a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
49 changes: 23 additions & 26 deletions src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1148,18 +1148,8 @@ bool S3fsCurl::UploadMultipartPostCallback(S3fsCurl* s3fscurl)
if(!s3fscurl){
return false;
}
headers_t::iterator it = s3fscurl->responseHeaders.find("ETag");
if (it == s3fscurl->responseHeaders.end()) {
return false;
}
// check etag(md5);
if(S3fsCurl::is_content_md5 && !etag_equals(it->second, s3fscurl->partdata.etag)){
return false;
}
s3fscurl->partdata.etaglist->at(s3fscurl->partdata.etagpos).assign(it->second);
s3fscurl->partdata.uploaded = true;

return true;
return s3fscurl->UploadMultipartPostComplete();
}

S3fsCurl* S3fsCurl::UploadMultipartPostRetryCallback(S3fsCurl* s3fscurl)
Expand Down Expand Up @@ -3434,17 +3424,8 @@ int S3fsCurl::UploadMultipartPostRequest(const char* tpath, int part_num, const

// request
if(0 == (result = RequestPerform())){
// check etag
headers_t::iterator it = responseHeaders.find("ETag");
if (it != responseHeaders.end()) {
if(S3fsCurl::is_content_md5 && !etag_equals(it->second, partdata.etag)){
result = -1;
}else{
partdata.uploaded = true;
}
}else{
result = -1;
}
// UploadMultipartPostComplete returns true on success -> convert to 0
result = !UploadMultipartPostComplete();
}

// closing
Expand Down Expand Up @@ -3565,6 +3546,22 @@ int S3fsCurl::CopyMultipartPostRequest(const char* from, const char* to, int par
return result;
}

bool S3fsCurl::UploadMultipartPostComplete()
{
headers_t::iterator it = responseHeaders.find("ETag");
if (it == responseHeaders.end()) {
return false;
}
// check etag(md5);
if(S3fsCurl::is_content_md5 && !etag_equals(it->second, partdata.etag)){
return false;
}
partdata.etaglist->at(partdata.etagpos).assign(it->second);
partdata.uploaded = true;

return true;
}

int S3fsCurl::MultipartHeadRequest(const char* tpath, off_t size, headers_t& meta, bool is_copy)
{
int result;
Expand Down Expand Up @@ -3645,14 +3642,14 @@ int S3fsCurl::MultipartUploadRequest(const char* tpath, headers_t& meta, int fd,
partdata.size = chunk;
b_partdata_startpos = partdata.startpos;
b_partdata_size = partdata.size;
partdata.add_etag_list(&list);

// upload part
if(0 != (result = UploadMultipartPostRequest(tpath, (list.size() + 1), upload_id))){
if(0 != (result = UploadMultipartPostRequest(tpath, list.size(), upload_id))){
S3FS_PRN_ERR("failed uploading part(%d)", result);
close(fd2);
return result;
}
list.push_back(partdata.etag);
DestroyCurlHandle();
}
close(fd2);
Expand Down Expand Up @@ -3683,15 +3680,15 @@ int S3fsCurl::MultipartUploadRequest(const string& upload_id, const char* tpath,
partdata.size = size;
b_partdata_startpos = partdata.startpos;
b_partdata_size = partdata.size;
partdata.add_etag_list(&list);

// upload part
int result;
if(0 != (result = UploadMultipartPostRequest(tpath, (list.size() + 1), upload_id))){
if(0 != (result = UploadMultipartPostRequest(tpath, list.size(), upload_id))){
S3FS_PRN_ERR("failed uploading part(%d)", result);
close(fd2);
return result;
}
list.push_back(partdata.etag);
DestroyCurlHandle();
close(fd2);

Expand Down
1 change: 1 addition & 0 deletions src/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class S3fsCurl

int UploadMultipartPostSetup(const char* tpath, int part_num, const std::string& upload_id);
int CopyMultipartPostRequest(const char* from, const char* to, int part_num, std::string& upload_id, headers_t& meta);
bool UploadMultipartPostComplete();

public:
// class methods
Expand Down

0 comments on commit df0ff3a

Please sign in to comment.