From a4f694c345b111cfb34781338dc99193045eb0d6 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 28 May 2024 09:17:45 +0900 Subject: [PATCH] Pass const std::string by reference (#2461) This is more idiomatic than by pointer. --- src/curl.h | 4 ++-- src/fdcache.cpp | 12 ++++++------ src/fdcache.h | 2 +- src/s3fs.cpp | 16 ++++++++-------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/curl.h b/src/curl.h index 9b4ecdbef6..2398b032e9 100644 --- a/src/curl.h +++ b/src/curl.h @@ -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); diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 1fc2ac4336..913ab33878 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -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() @@ -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; @@ -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() { diff --git a/src/fdcache.h b/src/fdcache.h index e294290288..0880f10618 100644 --- a/src/fdcache.h +++ b/src/fdcache.h @@ -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); diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 3a2c6cf9c1..46fe456686 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -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 doc(xmlReadMemory(encbody.c_str(), static_cast(encbody.size()), "", nullptr, 0), xmlFreeDoc); @@ -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 @@ -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-.amazonaws.com) and endpoint option with use_path_request_style option.", s3host.c_str(), endpoint.c_str()); @@ -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."); @@ -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());