Skip to content

Commit

Permalink
Pass const std::string by reference (s3fs-fuse#2461)
Browse files Browse the repository at this point in the history
This is more idiomatic than by pointer.
  • Loading branch information
gaul authored May 28, 2024
1 parent 2c532e8 commit a4f694c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ class S3fsCurl
const std::string& GetUrl() const { return url; }
const std::string& GetOp() const { return op; }
const headers_t* GetResponseHeaders() const { return &responseHeaders; }
const std::string* GetBodyData() const { return &bodydata; }
const std::string* GetHeadData() const { return &headdata; }
const std::string& GetBodyData() const { return bodydata; }
const std::string& GetHeadData() const { return headdata; }
CURLcode GetCurlCode() const { return curlCode; }
long GetLastResponseCode() const { return LastResponseCode; }
bool SetUseAhbe(bool ahbe);
Expand Down
12 changes: 6 additions & 6 deletions src/fdcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ bool FdManager::CheckCacheDirExist()
if(FdManager::cache_dir.empty()){
return true;
}
return IsDir(&cache_dir);
return IsDir(cache_dir);
}

off_t FdManager::GetEnsureFreeDiskSpace()
Expand Down Expand Up @@ -385,16 +385,16 @@ bool FdManager::SetTmpDir(const char *dir)
return true;
}

bool FdManager::IsDir(const std::string* dir)
bool FdManager::IsDir(const std::string& dir)
{
// check the directory
struct stat st;
if(0 != stat(dir->c_str(), &st)){
S3FS_PRN_ERR("could not stat() directory %s by errno(%d).", dir->c_str(), errno);
if(0 != stat(dir.c_str(), &st)){
S3FS_PRN_ERR("could not stat() directory %s by errno(%d).", dir.c_str(), errno);
return false;
}
if(!S_ISDIR(st.st_mode)){
S3FS_PRN_ERR("the directory %s is not a directory.", dir->c_str());
S3FS_PRN_ERR("the directory %s is not a directory.", dir.c_str());
return false;
}
return true;
Expand All @@ -405,7 +405,7 @@ bool FdManager::CheckTmpDirExist()
if(FdManager::tmp_dir.empty()){
return true;
}
return IsDir(&tmp_dir);
return IsDir(tmp_dir);
}

FILE* FdManager::MakeTempFile() {
Expand Down
2 changes: 1 addition & 1 deletion src/fdcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FdManager
private:
static off_t GetFreeDiskSpace(const char* path);
static off_t GetTotalDiskSpace(const char* path);
static bool IsDir(const std::string* dir);
static bool IsDir(const std::string& dir);
static int GetVfsStat(const char* path, struct statvfs* vfsbuf);

int GetPseudoFdCount(const char* path);
Expand Down
16 changes: 8 additions & 8 deletions src/s3fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3508,14 +3508,14 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
S3FS_PRN_ERR("ListBucketRequest returns with error.");
return result;
}
const std::string* body = s3fscurl.GetBodyData();
const std::string& body = s3fscurl.GetBodyData();

// [NOTE]
// CR code(\r) is replaced with LF(\n) by xmlReadMemory() function.
// To prevent that, only CR code is encoded by following function.
// The encoded CR code is decoded with append_objects_from_xml(_ex).
//
std::string encbody = get_encoded_cr_code(body->c_str());
std::string encbody = get_encoded_cr_code(body.c_str());

// xmlDocPtr
std::unique_ptr<xmlDoc, decltype(&xmlFreeDoc)> doc(xmlReadMemory(encbody.c_str(), static_cast<int>(encbody.size()), "", nullptr, 0), xmlFreeDoc);
Expand Down Expand Up @@ -4465,12 +4465,12 @@ static int s3fs_check_service()
if(300 <= responseCode && responseCode < 500){

// check region error(for putting message or retrying)
const std::string* body = s3fscurl.GetBodyData();
const std::string& body = s3fscurl.GetBodyData();
std::string expectregion;
std::string expectendpoint;

// Check if any case can be retried
if(check_region_error(body->c_str(), body->size(), expectregion)){
if(check_region_error(body.c_str(), body.size(), expectregion)){
// [NOTE]
// If endpoint is not specified(using us-east-1 region) and
// an error is encountered accessing a different region, we
Expand Down Expand Up @@ -4511,7 +4511,7 @@ static int s3fs_check_service()
S3FS_PRN_CRIT("The bucket region is not '%s'(default), it is correctly '%s'. You should specify endpoint(%s) option.", endpoint.c_str(), expectregion.c_str(), expectregion.c_str());
}

}else if(check_endpoint_error(body->c_str(), body->size(), expectendpoint)){
}else if(check_endpoint_error(body.c_str(), body.size(), expectendpoint)){
// redirect error
if(pathrequeststyle){
S3FS_PRN_CRIT("S3 service returned PermanentRedirect (current is url(%s) and endpoint(%s)). You need to specify correct url(http(s)://s3-<endpoint>.amazonaws.com) and endpoint option with use_path_request_style option.", s3host.c_str(), endpoint.c_str());
Expand All @@ -4520,7 +4520,7 @@ static int s3fs_check_service()
}
return EXIT_FAILURE;

}else if(check_invalid_sse_arg_error(body->c_str(), body->size())){
}else if(check_invalid_sse_arg_error(body.c_str(), body.size())){
// SSE argument error, so retry it without SSE
S3FS_PRN_CRIT("S3 service returned InvalidArgument(x-amz-server-side-encryption), so retry without adding x-amz-server-side-encryption.");

Expand Down Expand Up @@ -4551,8 +4551,8 @@ static int s3fs_check_service()
if(!do_retry && responseCode != 200 && responseCode != 301){
// parse error message if existed
std::string errMessage;
const std::string* body = s3fscurl.GetBodyData();
check_error_message(body->c_str(), body->size(), errMessage);
const std::string& body = s3fscurl.GetBodyData();
check_error_message(body.c_str(), body.size(), errMessage);

if(responseCode == 400){
S3FS_PRN_CRIT("Failed to check bucket and directory for mount point : Bad Request(host=%s, message=%s)", s3host.c_str(), errMessage.c_str());
Expand Down

0 comments on commit a4f694c

Please sign in to comment.