mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-23 13:58:24 +00:00
Prefer std::string::empty over length == 0 (#1679)
This is more concise.
This commit is contained in:
parent
4d39ea887e
commit
a100be9dce
@ -205,7 +205,7 @@ bool AdditionalHeader::AddHeader(headers_t& meta, const char* path) const
|
||||
}else{
|
||||
// directly comparing
|
||||
if(paddhead->basestring.length() < pathlength){
|
||||
if(0 == paddhead->basestring.length() || 0 == strcmp(&path[pathlength - paddhead->basestring.length()], paddhead->basestring.c_str())){
|
||||
if(paddhead->basestring.empty() || 0 == strcmp(&path[pathlength - paddhead->basestring.length()], paddhead->basestring.c_str())){
|
||||
// match -> adding header
|
||||
meta[paddhead->headkey] = paddhead->headvalue;
|
||||
}
|
||||
|
@ -953,7 +953,7 @@ bool S3fsCurl::LoadEnvSseKmsid()
|
||||
bool S3fsCurl::GetSseKey(std::string& md5, std::string& ssekey)
|
||||
{
|
||||
for(sseckeylist_t::const_iterator iter = S3fsCurl::sseckeys.begin(); iter != S3fsCurl::sseckeys.end(); ++iter){
|
||||
if(0 == md5.length() || md5 == (*iter).begin()->first){
|
||||
if(md5.empty() || md5 == (*iter).begin()->first){
|
||||
md5 = iter->begin()->first;
|
||||
ssekey = iter->begin()->second;
|
||||
return true;
|
||||
@ -2658,7 +2658,7 @@ void S3fsCurl::insertV4Headers()
|
||||
break;
|
||||
}
|
||||
|
||||
if(b_infile != NULL && 0 == payload_hash.length()){
|
||||
if(b_infile != NULL && payload_hash.empty()){
|
||||
S3FS_PRN_ERR("Failed to make SHA256.");
|
||||
// TODO: propagate error
|
||||
}
|
||||
|
@ -329,11 +329,11 @@ class S3fsCurl
|
||||
static bool SetAccessKeyWithSessionToken(const char* AccessKeyId, const char* SecretAccessKey, const char * SessionToken);
|
||||
static bool IsSetAccessKeyID()
|
||||
{
|
||||
return (0 < S3fsCurl::AWSAccessKeyId.size());
|
||||
return !S3fsCurl::AWSAccessKeyId.empty();
|
||||
}
|
||||
static bool IsSetAccessKeys()
|
||||
{
|
||||
return (0 < S3fsCurl::IAM_role.size() || ((0 < S3fsCurl::AWSAccessKeyId.size() || S3fsCurl::is_ibm_iam_auth) && 0 < S3fsCurl::AWSSecretAccessKey.size()));
|
||||
return !S3fsCurl::IAM_role.empty() || ((!S3fsCurl::AWSAccessKeyId.empty() || S3fsCurl::is_ibm_iam_auth) && !S3fsCurl::AWSSecretAccessKey.empty());
|
||||
}
|
||||
static long SetSslVerifyHostname(long value);
|
||||
static long GetSslVerifyHostname() { return S3fsCurl::ssl_verify_hostname; }
|
||||
|
@ -145,7 +145,7 @@ std::string get_sorted_header_keys(const struct curl_slist* list)
|
||||
}
|
||||
strkey.erase(pos);
|
||||
}
|
||||
if(0 < sorted_headers.length()){
|
||||
if(!sorted_headers.empty()){
|
||||
sorted_headers += ";";
|
||||
}
|
||||
sorted_headers += lower(strkey);
|
||||
@ -317,7 +317,7 @@ bool make_md5_from_binary(const char* pstr, size_t length, std::string& md5)
|
||||
}
|
||||
// base64 md5
|
||||
md5 = s3fs_get_content_md5(fd);
|
||||
if(0 == md5.length()){
|
||||
if(md5.empty()){
|
||||
S3FS_PRN_ERR("Failed to make MD5.");
|
||||
fclose(fp);
|
||||
return false;
|
||||
|
12
src/s3fs.cpp
12
src/s3fs.cpp
@ -277,7 +277,7 @@ static int chk_dir_object_type(const char* path, std::string& newpath, std::stri
|
||||
nowpath = "";
|
||||
}else{
|
||||
nowpath = newpath;
|
||||
if(0 < nowpath.length() && '/' == *nowpath.rbegin()){
|
||||
if(!nowpath.empty() && '/' == *nowpath.rbegin()){
|
||||
// "dir/" type
|
||||
(*pType) = DIRTYPE_NEW;
|
||||
}else{
|
||||
@ -2694,7 +2694,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
||||
|
||||
query_prefix += "&prefix=";
|
||||
s3_realpath = get_realpath(path);
|
||||
if(0 == s3_realpath.length() || '/' != *s3_realpath.rbegin()){
|
||||
if(s3_realpath.empty() || '/' != *s3_realpath.rbegin()){
|
||||
// last word must be "/"
|
||||
query_prefix += urlEncode(s3_realpath.substr(1) + "/");
|
||||
}else{
|
||||
@ -2764,7 +2764,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
|
||||
truncated = false;
|
||||
}else{
|
||||
next_marker = s3_realpath.substr(1);
|
||||
if(0 == s3_realpath.length() || '/' != *s3_realpath.rbegin()){
|
||||
if(s3_realpath.empty() || '/' != *s3_realpath.rbegin()){
|
||||
next_marker += "/";
|
||||
}
|
||||
next_marker += lastname;
|
||||
@ -2858,7 +2858,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(','); 0 < restxattrs.length(); 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) : std::string("")), pair_nextpos = restxattrs.find_first_of(',')){
|
||||
std::string pair = pair_nextpos != std::string::npos ? restxattrs.substr(0, pair_nextpos) : restxattrs;
|
||||
std::string key;
|
||||
PXATTRVAL pval = NULL;
|
||||
@ -3190,7 +3190,7 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
|
||||
// calculate total name length
|
||||
size_t total = 0;
|
||||
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
|
||||
if(0 < xiter->first.length()){
|
||||
if(!xiter->first.empty()){
|
||||
total += xiter->first.length() + 1;
|
||||
}
|
||||
}
|
||||
@ -3213,7 +3213,7 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
|
||||
// copy to list
|
||||
char* setpos = list;
|
||||
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
|
||||
if(0 < xiter->first.length()){
|
||||
if(!xiter->first.empty()){
|
||||
strcpy(setpos, xiter->first.c_str());
|
||||
setpos = &setpos[strlen(setpos) + 1];
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ static char* get_object_name(xmlDocPtr doc, xmlNodePtr node, const char* path)
|
||||
if(strlen(dirpath) > strlen(basepath)){
|
||||
withdirname = &dirpath[strlen(basepath)];
|
||||
}
|
||||
if(0 < withdirname.length() && '/' != *withdirname.rbegin()){
|
||||
if(!withdirname.empty() && '/' != *withdirname.rbegin()){
|
||||
withdirname += "/";
|
||||
}
|
||||
withdirname += mybname;
|
||||
@ -378,7 +378,7 @@ int append_objects_from_xml_ex(const char* path, xmlDocPtr doc, xmlXPathContextP
|
||||
xmlXPathFreeObject(ETag);
|
||||
}
|
||||
}
|
||||
if(!head.insert(name, (0 < stretag.length() ? stretag.c_str() : NULL), is_dir)){
|
||||
if(!head.insert(name, (!stretag.empty() ? stretag.c_str() : NULL), is_dir)){
|
||||
S3FS_PRN_ERR("insert_object returns with error.");
|
||||
xmlXPathFreeObject(key);
|
||||
xmlXPathFreeObject(contents_xp);
|
||||
|
@ -165,7 +165,7 @@ std::string S3ObjList::GetNormalizedName(const char* name) const
|
||||
if(NULL == (ps3obj = GetS3Obj(name))){
|
||||
return std::string("");
|
||||
}
|
||||
if(0 == (ps3obj->normalname).length()){
|
||||
if(ps3obj->normalname.empty()){
|
||||
return std::string(name);
|
||||
}
|
||||
return ps3obj->normalname;
|
||||
@ -219,7 +219,7 @@ bool S3ObjList::GetNameList(s3obj_list_t& list, bool OnlyNormalized, bool CutSla
|
||||
s3obj_t::const_iterator iter;
|
||||
|
||||
for(iter = objects.begin(); objects.end() != iter; ++iter){
|
||||
if(OnlyNormalized && 0 != (*iter).second.normalname.length()){
|
||||
if(OnlyNormalized && !iter->second.normalname.empty()){
|
||||
continue;
|
||||
}
|
||||
std::string name = (*iter).first;
|
||||
@ -250,7 +250,7 @@ bool S3ObjList::MakeHierarchizedList(s3obj_list_t& list, bool haveSlash)
|
||||
// check hierarchized directory
|
||||
for(std::string::size_type pos = strtmp.find_last_of('/'); std::string::npos != pos; pos = strtmp.find_last_of('/')){
|
||||
strtmp.erase(pos);
|
||||
if(0 == strtmp.length() || "/" == strtmp){
|
||||
if(strtmp.empty() || "/" == strtmp){
|
||||
break;
|
||||
}
|
||||
if(h_map.end() == h_map.find(strtmp)){
|
||||
|
Loading…
x
Reference in New Issue
Block a user