mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-31 11:51:49 +00:00
parent
c5fb42ff10
commit
61df7bf42c
14
src/curl.cpp
14
src/curl.cpp
@ -3393,7 +3393,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
|
||||
int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
{
|
||||
struct stat st;
|
||||
FILE* file = nullptr;
|
||||
std::unique_ptr<FILE, decltype(&s3fs_fclose)> file(nullptr, &s3fs_fclose);
|
||||
|
||||
S3FS_PRN_INFO3("[tpath=%s]", SAFESTRPTR(tpath));
|
||||
|
||||
@ -3409,23 +3409,20 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
// The fd should not be closed here, so call dup here to duplicate it.
|
||||
//
|
||||
int fd2;
|
||||
if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || nullptr == (file = fdopen(fd2, "rb"))){
|
||||
if(-1 == (fd2 = dup(fd)) || -1 == fstat(fd2, &st) || 0 != lseek(fd2, 0, SEEK_SET) || nullptr == (file = {fdopen(fd2, "rb"), &s3fs_fclose})){
|
||||
S3FS_PRN_ERR("Could not duplicate file descriptor(errno=%d)", errno);
|
||||
if(-1 != fd2){
|
||||
close(fd2);
|
||||
}
|
||||
return -errno;
|
||||
}
|
||||
b_infile = file;
|
||||
b_infile = file.get();
|
||||
}else{
|
||||
// This case is creating zero byte object.(calling by create_file_object())
|
||||
S3FS_PRN_INFO3("create zero byte file object.");
|
||||
}
|
||||
|
||||
if(!CreateCurlHandle()){
|
||||
if(file){
|
||||
fclose(file);
|
||||
}
|
||||
return -EIO;
|
||||
}
|
||||
std::string resource;
|
||||
@ -3511,7 +3508,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_INFILESIZE_LARGE, static_cast<curl_off_t>(st.st_size))){ // Content-Length
|
||||
return -EIO;
|
||||
}
|
||||
if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_INFILE, file)){
|
||||
if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_INFILE, file.get())){
|
||||
return -EIO;
|
||||
}
|
||||
}else{
|
||||
@ -3528,9 +3525,6 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
|
||||
int result = RequestPerform();
|
||||
result = MapPutErrorResponse(result);
|
||||
bodydata.clear();
|
||||
if(file){
|
||||
fclose(file);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -307,13 +307,10 @@ bool FdManager::HaveLseekHole()
|
||||
}
|
||||
|
||||
// create temporary file
|
||||
FILE* ptmpfp;
|
||||
int fd;
|
||||
if(nullptr == (ptmpfp = MakeTempFile()) || -1 == (fd = fileno(ptmpfp))){
|
||||
int fd;
|
||||
std::unique_ptr<FILE, decltype(&s3fs_fclose)> ptmpfp(MakeTempFile(), &s3fs_fclose);
|
||||
if(nullptr == ptmpfp || -1 == (fd = fileno(ptmpfp.get()))){
|
||||
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
|
||||
if(ptmpfp){
|
||||
fclose(ptmpfp);
|
||||
}
|
||||
FdManager::checked_lseek = true;
|
||||
FdManager::have_lseek_hole = false;
|
||||
return false;
|
||||
@ -333,7 +330,6 @@ bool FdManager::HaveLseekHole()
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
fclose(ptmpfp);
|
||||
|
||||
FdManager::checked_lseek = true;
|
||||
FdManager::have_lseek_hole = result;
|
||||
|
@ -1156,13 +1156,10 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si
|
||||
FdManager::get()->ChangeEntityToTempPath(this, path.c_str());
|
||||
|
||||
// open temporary file
|
||||
FILE* ptmpfp;
|
||||
int tmpfd;
|
||||
if(nullptr == (ptmpfp = FdManager::MakeTempFile()) || -1 ==(tmpfd = fileno(ptmpfp))){
|
||||
int tmpfd;
|
||||
std::unique_ptr<FILE, decltype(&s3fs_fclose)> ptmpfp(FdManager::MakeTempFile(), &s3fs_fclose);
|
||||
if(nullptr == ptmpfp || -1 == (tmpfd = fileno(ptmpfp.get()))){
|
||||
S3FS_PRN_ERR("failed to open temporary file by errno(%d)", errno);
|
||||
if(ptmpfp){
|
||||
fclose(ptmpfp);
|
||||
}
|
||||
return (0 == errno ? -EIO : -errno);
|
||||
}
|
||||
|
||||
@ -1284,9 +1281,6 @@ int FdEntity::NoCacheLoadAndPost(PseudoFdInfo* pseudo_obj, off_t start, off_t si
|
||||
}
|
||||
}
|
||||
|
||||
// close temporary
|
||||
fclose(ptmpfp);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -567,6 +567,14 @@ std::string s3fs_str_realtime()
|
||||
return str(*s3fs_realtime(ts));
|
||||
}
|
||||
|
||||
int s3fs_fclose(FILE* fp)
|
||||
{
|
||||
if(fp == nullptr){
|
||||
return 0;
|
||||
}
|
||||
return fclose(fp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Local variables:
|
||||
* tab-width: 4
|
||||
|
@ -74,6 +74,9 @@ std::string str_stat_time(const struct stat& st, stat_time_type type);
|
||||
struct timespec* s3fs_realtime(struct timespec& ts);
|
||||
std::string s3fs_str_realtime();
|
||||
|
||||
// Wrap fclose since it is illegal to take the address of a stdlib function
|
||||
int s3fs_fclose(FILE* fp);
|
||||
|
||||
#endif // S3FS_S3FS_UTIL_H_
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user