Remove unneeded explicit std::string constructors (#2273)

std::string(const char*) implicitly constructs these.  The remaining call sites
requires string literals from C++14.
This commit is contained in:
Andrew Gaul 2023-08-17 22:12:28 +09:00 committed by GitHub
parent 7f30353fb9
commit b2bb12fd2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 56 additions and 54 deletions

View File

@ -588,7 +588,7 @@ bool StatCache::DelStat(const char* key, AutoLock::Type locktype)
AutoLock lock(&StatCache::stat_cache_lock, locktype);
stat_cache_t::iterator iter;
if(stat_cache.end() != (iter = stat_cache.find(std::string(key)))){
if(stat_cache.end() != (iter = stat_cache.find(key))){
stat_cache.erase(iter);
}
if(0 < strlen(key) && 0 != strcmp(key, "/")){
@ -740,7 +740,7 @@ bool StatCache::DelSymlink(const char* key, AutoLock::Type locktype)
AutoLock lock(&StatCache::stat_cache_lock, locktype);
symlink_cache_t::iterator iter;
if(symlink_cache.end() != (iter = symlink_cache.find(std::string(key)))){
if(symlink_cache.end() != (iter = symlink_cache.find(key))){
symlink_cache.erase(iter);
}
S3FS_MALLOCTRIM(0);

View File

@ -32,7 +32,7 @@ std::string s3fs_get_content_md5(int fd)
md5_t md5;
if(!s3fs_md5_fd(fd, 0, -1, &md5)){
// TODO: better return value?
return std::string("");
return "";
}
return s3fs_base64(md5.data(), md5.size());
}
@ -42,7 +42,8 @@ std::string s3fs_sha256_hex_fd(int fd, off_t start, off_t size)
sha256_t sha256;
if(!s3fs_sha256_fd(fd, start, size, &sha256)){
return std::string("");
// TODO: better return value?
return "";
}
std::string sha256hex = s3fs_hex_lower(sha256.data(), sha256.size());

View File

@ -1492,7 +1492,7 @@ int S3fsCurl::ParallelMixMultipartUploadRequest(const char* tpath, headers_t& me
std::string srcresource;
std::string srcurl;
MakeUrlResource(get_realpath(tpath).c_str(), srcresource, srcurl);
meta["Content-Type"] = S3fsCurl::LookupMimeType(std::string(tpath));
meta["Content-Type"] = S3fsCurl::LookupMimeType(tpath);
meta["x-amz-copy-source"] = srcresource;
// Initialize S3fsMultiCurl
@ -2897,7 +2897,7 @@ void S3fsCurl::insertV2Headers(const std::string& access_key_id, const std::stri
if(!S3fsCurl::IsPublicBucket()){
std::string Signature = CalcSignatureV2(op, get_header_value(requestHeaders, "Content-MD5"), get_header_value(requestHeaders, "Content-Type"), date, resource, secret_access_key, access_token);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Authorization", std::string("AWS " + access_key_id + ":" + Signature).c_str());
requestHeaders = curl_slist_sort_insert(requestHeaders, "Authorization", ("AWS " + access_key_id + ":" + Signature).c_str());
}
}
@ -2974,7 +2974,7 @@ int S3fsCurl::GetIAMv2ApiToken(const char* token_url, int token_ttl, const char*
return -EIO;
}
response.erase();
url = std::string(token_url);
url = token_url;
if(!CreateCurlHandle()){
return -EIO;
}
@ -3053,7 +3053,8 @@ bool S3fsCurl::GetIAMCredentials(const char* cred_url, const char* iam_v2_token,
// make contents
postContent += "grant_type=urn:ibm:params:oauth:grant-type:apikey";
postContent += "&response_type=cloud_iam";
postContent += "&apikey=" + std::string(ibm_secret_access_key);
postContent += "&apikey=";
postContent += ibm_secret_access_key;
// set postdata
postdata = reinterpret_cast<const unsigned char*>(postContent.c_str());
@ -3329,7 +3330,7 @@ int S3fsCurl::PutHeadRequest(const char* tpath, headers_t& meta, bool is_copy)
responseHeaders.clear();
bodydata.Clear();
std::string contype = S3fsCurl::LookupMimeType(std::string(tpath));
std::string contype = S3fsCurl::LookupMimeType(tpath);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
// Make request headers
@ -3470,7 +3471,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", strMD5.c_str());
}
std::string contype = S3fsCurl::LookupMimeType(std::string(tpath));
std::string contype = S3fsCurl::LookupMimeType(tpath);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
@ -3791,7 +3792,7 @@ int S3fsCurl::PreMultipartPostRequest(const char* tpath, headers_t& meta, std::s
bodydata.Clear();
responseHeaders.clear();
std::string contype = S3fsCurl::LookupMimeType(std::string(tpath));
std::string contype = S3fsCurl::LookupMimeType(tpath);
for(headers_t::iterator iter = meta.begin(); iter != meta.end(); ++iter){
std::string key = lower(iter->first);
@ -4194,7 +4195,7 @@ int S3fsCurl::CopyMultipartPostSetup(const char* from, const char* to, int part_
bodydata.Clear();
headdata.Clear();
std::string contype = S3fsCurl::LookupMimeType(std::string(to));
std::string contype = S3fsCurl::LookupMimeType(to);
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-Type", contype.c_str());
// Make request headers
@ -4403,7 +4404,7 @@ int S3fsCurl::MultipartRenameRequest(const char* from, const char* to, headers_t
std::string srcurl;
MakeUrlResource(get_realpath(from).c_str(), srcresource, srcurl);
meta["Content-Type"] = S3fsCurl::LookupMimeType(std::string(to));
meta["Content-Type"] = S3fsCurl::LookupMimeType(to);
meta["x-amz-copy-source"] = srcresource;
if(0 != (result = PreMultipartPostRequest(to, meta, upload_id, true))){

View File

@ -61,8 +61,8 @@ struct curl_slist* curl_slist_sort_insert(struct curl_slist* list, const char* k
}
// key & value are trimmed and lower (only key)
std::string strkey = trim(std::string(key));
std::string strval = value ? trim(std::string(value)) : "";
std::string strkey = trim(key);
std::string strval = value ? trim(value) : "";
std::string strnew = key + std::string(": ") + strval;
char* data;
if(nullptr == (data = strdup(strnew.c_str()))){
@ -107,7 +107,7 @@ struct curl_slist* curl_slist_remove(struct curl_slist* list, const char* key)
return list;
}
std::string strkey = trim(std::string(key));
std::string strkey = trim(key);
struct curl_slist **p = &list;
while(*p){
std::string strcur = (*p)->data;
@ -259,8 +259,8 @@ std::string prepare_url(const char* url)
std::string uri;
std::string hostname;
std::string path;
std::string url_str = std::string(url);
std::string token = std::string("/") + S3fsCred::GetBucket();
std::string url_str = url;
std::string token = "/" + S3fsCred::GetBucket();
size_t bucket_pos;
size_t bucket_length = token.size();
size_t uri_length = 0;

View File

@ -489,7 +489,7 @@ FdEntity* FdManager::GetFdEntity(const char* path, int& existfd, bool newfd, Aut
}
AutoLock auto_lock(&FdManager::fd_manager_lock, locktype);
fdent_map_t::iterator iter = fent.find(std::string(path));
fdent_map_t::iterator iter = fent.find(path);
if(fent.end() != iter && iter->second){
if(-1 == existfd){
if(newfd){
@ -544,7 +544,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
AutoLock auto_lock(&FdManager::fd_manager_lock);
// search in mapping by key(path)
fdent_map_t::iterator iter = fent.find(std::string(path));
fdent_map_t::iterator iter = fent.find(path);
if(fent.end() == iter && !force_tmpfile && !FdManager::IsCacheDir()){
// If the cache directory is not specified, s3fs opens a temporary file
// when the file is opened.
@ -602,7 +602,7 @@ FdEntity* FdManager::Open(int& fd, const char* path, const headers_t* pmeta, off
if(!cache_path.empty()){
// using cache
fent[std::string(path)] = ent;
fent[path] = ent;
}else{
// not using cache, so the key of fdentity is set not really existing path.
// (but not strictly unexisting path.)

View File

@ -1035,7 +1035,7 @@ bool FdEntity::SetContentType(const char* path)
return false;
}
AutoLock auto_lock(&fdent_lock);
orgmeta["Content-Type"] = S3fsCurl::LookupMimeType(std::string(path));
orgmeta["Content-Type"] = S3fsCurl::LookupMimeType(path);
return true;
}

View File

@ -328,7 +328,7 @@ int SyncFiller::Fill(const char *name, const struct stat *stbuf, off_t off)
AutoLock auto_lock(&filler_lock);
int result = 0;
if(filled.insert(std::string(name)).second){
if(filled.insert(name).second){
result = filler_func(filler_buff, name, stbuf, off);
}
return result;
@ -1072,7 +1072,7 @@ static int s3fs_readlink(const char* _path, char* buf, size_t size)
std::string strValue;
// check symbolic link cache
if(!StatCache::getStatCacheData()->GetSymlink(std::string(path), strValue)){
if(!StatCache::getStatCacheData()->GetSymlink(path, strValue)){
// not found in cache, then open the path
{ // scope for AutoFdEntity
AutoFdEntity autoent;
@ -1101,7 +1101,7 @@ static int s3fs_readlink(const char* _path, char* buf, size_t size)
}
// check buf if it has space words.
strValue = trim(std::string(buf));
strValue = trim(buf);
// decode wtf8. This will always be shorter
if(use_wtf8){
@ -1109,7 +1109,7 @@ static int s3fs_readlink(const char* _path, char* buf, size_t size)
}
// add symbolic link cache
if(!StatCache::getStatCacheData()->AddSymlink(std::string(path), strValue)){
if(!StatCache::getStatCacheData()->AddSymlink(path, strValue)){
S3FS_PRN_ERR("failed to add symbolic link cache for %s", path);
}
}
@ -1129,7 +1129,7 @@ static int create_file_object(const char* path, mode_t mode, uid_t uid, gid_t gi
std::string strnow = s3fs_str_realtime();
headers_t meta;
meta["Content-Type"] = S3fsCurl::LookupMimeType(std::string(path));
meta["Content-Type"] = S3fsCurl::LookupMimeType(path);
meta["x-amz-meta-uid"] = std::to_string(uid);
meta["x-amz-meta-gid"] = std::to_string(gid);
meta["x-amz-meta-mode"] = std::to_string(mode);
@ -1260,8 +1260,8 @@ static int create_directory_object(const char* path, mode_t mode, const struct t
meta["x-amz-meta-ctime"] = str(ts_ctime);
if(pxattrvalue){
S3FS_PRN_DBG("Set xattrs = %s", urlDecode(std::string(pxattrvalue)).c_str());
meta["x-amz-meta-xattr"] = std::string(pxattrvalue);
S3FS_PRN_DBG("Set xattrs = %s", urlDecode(pxattrvalue).c_str());
meta["x-amz-meta-xattr"] = pxattrvalue;
}
S3fsCurl s3fscurl;
@ -1446,7 +1446,7 @@ static int s3fs_symlink(const char* _from, const char* _to)
std::string strnow = s3fs_str_realtime();
headers_t headers;
headers["Content-Type"] = std::string("application/octet-stream"); // Static
headers["Content-Type"] = "application/octet-stream"; // Static
headers["x-amz-meta-mode"] = std::to_string(S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO);
headers["x-amz-meta-atime"] = strnow;
headers["x-amz-meta-ctime"] = strnow;
@ -1467,7 +1467,7 @@ static int s3fs_symlink(const char* _from, const char* _to)
return -errno;
}
// write(without space words)
strFrom = trim(std::string(from));
strFrom = trim(from);
ssize_t from_size = static_cast<ssize_t>(strFrom.length());
ssize_t ressize;
if(from_size != (ressize = ent->Write(autoent.GetPseudoFd(), strFrom.c_str(), 0, from_size))){
@ -1486,7 +1486,7 @@ static int s3fs_symlink(const char* _from, const char* _to)
}
StatCache::getStatCacheData()->DelStat(to);
if(!StatCache::getStatCacheData()->AddSymlink(std::string(to), strFrom)){
if(!StatCache::getStatCacheData()->AddSymlink(to, strFrom)){
S3FS_PRN_ERR("failed to add symbolic link cache for %s", to);
}
@ -1527,7 +1527,7 @@ static int rename_object(const char* from, const char* to, bool update_ctime)
meta["x-amz-meta-ctime"] = s3fs_str_realtime();
}
meta["x-amz-copy-source"] = urlEncodePath(service_path + S3fsCred::GetBucket() + get_realpath(strSourcePath.c_str()));
meta["Content-Type"] = S3fsCurl::LookupMimeType(std::string(to));
meta["Content-Type"] = S3fsCurl::LookupMimeType(to);
meta["x-amz-metadata-directive"] = "REPLACE";
std::string xattrvalue;
@ -2783,7 +2783,7 @@ static int s3fs_truncate(const char* _path, off_t size)
}
std::string strnow = s3fs_str_realtime();
meta["Content-Type"] = std::string("application/octet-stream"); // Static
meta["Content-Type"] = "application/octet-stream"; // Static
meta["x-amz-meta-mode"] = std::to_string(S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO);
meta["x-amz-meta-ctime"] = strnow;
meta["x-amz-meta-mtime"] = strnow;
@ -3101,7 +3101,7 @@ static int s3fs_release(const char* _path, struct fuse_file_info* fi)
// [NOTE]
// All opened file's stats is cached with no truncate flag.
// Thus we unset it here.
StatCache::getStatCacheData()->ChangeNoTruncateFlag(std::string(path), false);
StatCache::getStatCacheData()->ChangeNoTruncateFlag(path, false);
// [NOTICE]
// At first, we remove stats cache.
@ -3349,7 +3349,7 @@ static int readdir_multi_head(const char* path, const S3ObjList& head, void* buf
umask(dirmask);
headers_t dummy_header;
dummy_header["Content-Type"] = std::string("application/x-directory"); // directory
dummy_header["Content-Type"] = "application/x-directory"; // directory
dummy_header["x-amz-meta-uid"] = std::to_string(is_s3fs_uid ? s3fs_uid : geteuid());
dummy_header["x-amz-meta-gid"] = std::to_string(is_s3fs_gid ? s3fs_gid : getegid());
dummy_header["x-amz-meta-mode"] = std::to_string(S_IFDIR | (~dirmask & (S_IRWXU | S_IRWXG | S_IRWXO)));
@ -3732,7 +3732,7 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
}
// parse each key:val
for(size_t pair_nextpos = restxattrs.find_first_of(','); !restxattrs.empty(); restxattrs = (pair_nextpos != std::string::npos ? restxattrs.substr(pair_nextpos + 1) : std::string("")), pair_nextpos = restxattrs.find_first_of(',')){
for(size_t pair_nextpos = restxattrs.find_first_of(','); !restxattrs.empty(); restxattrs = (pair_nextpos != std::string::npos ? restxattrs.substr(pair_nextpos + 1) : ""), pair_nextpos = restxattrs.find_first_of(',')){
std::string pair = pair_nextpos != std::string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs;
std::string key;
xattr_value val;
@ -4191,7 +4191,7 @@ static int s3fs_removexattr(const char* path, const char* name)
if(!xattrs.empty()){
updatemeta["x-amz-meta-xattr"] = build_xattrs(xattrs);
}else{
updatemeta["x-amz-meta-xattr"] = std::string(""); // This is a special case. If empty, this header will eventually be removed.
updatemeta["x-amz-meta-xattr"] = ""; // This is a special case. If empty, this header will eventually be removed.
}
// check opened file handle.

View File

@ -569,8 +569,8 @@ bool S3fsCred::SetIAMCredentials(const char* response, AutoLock::Type type)
}
AWSAccessTokenExpire = static_cast<time_t>(tmp_expire);
}else{
AWSAccessKeyId = keyval[std::string(S3fsCred::IAMCRED_ACCESSKEYID)];
AWSSecretAccessKey = keyval[std::string(S3fsCred::IAMCRED_SECRETACCESSKEY)];
AWSAccessKeyId = keyval[S3fsCred::IAMCRED_ACCESSKEYID];
AWSSecretAccessKey = keyval[S3fsCred::IAMCRED_SECRETACCESSKEY];
AWSAccessTokenExpire = cvtIAMExpireStringToTime(keyval[IAM_expiry_field].c_str());
}
return true;

View File

@ -108,12 +108,12 @@ std::string get_username(uid_t uid)
if(0 != result){
S3FS_PRN_ERR("could not get pw information(%d).", result);
return std::string("");
return "";
}
// check pw
if(nullptr == ppwinfo){
return std::string("");
return "";
}
std::string name = SAFESTRPTR(ppwinfo->pw_name);
return name;
@ -222,7 +222,7 @@ std::string mydirname(const std::string& path)
std::string mydirname(const char* path)
{
if(!path || '\0' == path[0]){
return std::string("");
return "";
}
char *buf = strdup(path);
@ -243,7 +243,7 @@ std::string mybasename(const std::string& path)
std::string mybasename(const char* path)
{
if(!path || '\0' == path[0]){
return std::string("");
return "";
}
char *buf = strdup(path);

View File

@ -158,8 +158,8 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
}
// Make dir path and filename
std::string strdirpath = mydirname(std::string(reinterpret_cast<char*>(fullpath)));
std::string strmybpath = mybasename(std::string(reinterpret_cast<char*>(fullpath)));
std::string strdirpath = mydirname(reinterpret_cast<const char*>(fullpath));
std::string strmybpath = mybasename(reinterpret_cast<const char*>(fullpath));
const char* dirpath = strdirpath.c_str();
const char* mybname = strmybpath.c_str();
const char* basepath= (path && '/' == path[0]) ? &path[1] : path;

View File

@ -84,7 +84,7 @@ bool S3ObjList::insert(const char* name, const char* etag, bool is_dir)
(*iter).second.orgname = orgname;
(*iter).second.is_dir = is_dir;
if(etag){
(*iter).second.etag = std::string(etag); // over write
(*iter).second.etag = etag; // over write
}
}else{
// add new object
@ -145,10 +145,10 @@ std::string S3ObjList::GetOrgName(const char* name) const
const s3obj_entry* ps3obj;
if(!name || '\0' == name[0]){
return std::string("");
return "";
}
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
return "";
}
return ps3obj->orgname;
}
@ -158,13 +158,13 @@ std::string S3ObjList::GetNormalizedName(const char* name) const
const s3obj_entry* ps3obj;
if(!name || '\0' == name[0]){
return std::string("");
return "";
}
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
return "";
}
if(ps3obj->normalname.empty()){
return std::string(name);
return name;
}
return ps3obj->normalname;
}
@ -174,10 +174,10 @@ std::string S3ObjList::GetETag(const char* name) const
const s3obj_entry* ps3obj;
if(!name || '\0' == name[0]){
return std::string("");
return "";
}
if(nullptr == (ps3obj = GetS3Obj(name))){
return std::string("");
return "";
}
return ps3obj->etag;
}