Merge pull request #924 from gaul/clang-tidy/empty

Prefer empty over size checks
This commit is contained in:
Takeshi Nakatani 2019-01-27 15:04:52 +09:00 committed by GitHub
commit 807a618cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 44 additions and 44 deletions

View File

@ -89,7 +89,7 @@ bool AdditionalHeader::Load(const char* file)
if('#' == line[0]){ if('#' == line[0]){
continue; continue;
} }
if(0 == line.size()){ if(line.empty()){
continue; continue;
} }
// load a line // load a line
@ -108,8 +108,8 @@ bool AdditionalHeader::Load(const char* file)
} }
// check it // check it
if(0 == head.size()){ if(head.empty()){
if(0 == key.size()){ if(key.empty()){
continue; continue;
} }
S3FS_PRN_ERR("file format error: %s key(suffix) is no HTTP header value.", key.c_str()); S3FS_PRN_ERR("file format error: %s key(suffix) is no HTTP header value.", key.c_str());

View File

@ -607,7 +607,7 @@ bool S3fsCurl::InitMimeType(const char* MimeFile)
if(line[0]=='#'){ if(line[0]=='#'){
continue; continue;
} }
if(line.size() == 0){ if(line.empty()){
continue; continue;
} }
@ -617,7 +617,7 @@ bool S3fsCurl::InitMimeType(const char* MimeFile)
while(tmp){ while(tmp){
string ext; string ext;
tmp >> ext; tmp >> ext;
if(ext.size() == 0){ if(ext.empty()){
continue; continue;
} }
S3fsCurl::mimeTypes[ext] = mimeType; S3fsCurl::mimeTypes[ext] = mimeType;
@ -704,7 +704,7 @@ bool S3fsCurl::LocateBundle(void)
// See if environment variable CURL_CA_BUNDLE is set // See if environment variable CURL_CA_BUNDLE is set
// if so, check it, if it is a good path, then set the // if so, check it, if it is a good path, then set the
// curl_ca_bundle variable to it // curl_ca_bundle variable to it
if(0 == S3fsCurl::curl_ca_bundle.size()){ if(S3fsCurl::curl_ca_bundle.empty()){
char* CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE"); char* CURL_CA_BUNDLE = getenv("CURL_CA_BUNDLE");
if(CURL_CA_BUNDLE != NULL) { if(CURL_CA_BUNDLE != NULL) {
// check for existence and readability of the file // check for existence and readability of the file
@ -960,7 +960,7 @@ storage_class_t S3fsCurl::SetStorageClass(storage_class_t storage_class)
bool S3fsCurl::PushbackSseKeys(string& onekey) bool S3fsCurl::PushbackSseKeys(string& onekey)
{ {
onekey = trim(onekey); onekey = trim(onekey);
if(0 == onekey.size()){ if(onekey.empty()){
return false; return false;
} }
if('#' == onekey[0]){ if('#' == onekey[0]){
@ -1043,7 +1043,7 @@ bool S3fsCurl::SetSseCKeys(const char* filepath)
while(getline(ssefs, line)){ while(getline(ssefs, line)){
S3fsCurl::PushbackSseKeys(line); S3fsCurl::PushbackSseKeys(line);
} }
if(0 == S3fsCurl::sseckeys.size()){ if(S3fsCurl::sseckeys.empty()){
S3FS_PRN_ERR("There is no SSE Key in file(%s).", filepath); S3FS_PRN_ERR("There is no SSE Key in file(%s).", filepath);
return false; return false;
} }
@ -1070,7 +1070,7 @@ bool S3fsCurl::FinalCheckSse(void)
}else if(SSE_S3 == S3fsCurl::ssetype){ }else if(SSE_S3 == S3fsCurl::ssetype){
S3fsCurl::ssekmsid.erase(); S3fsCurl::ssekmsid.erase();
}else if(SSE_C == S3fsCurl::ssetype){ }else if(SSE_C == S3fsCurl::ssetype){
if(0 == S3fsCurl::sseckeys.size()){ if(S3fsCurl::sseckeys.empty()){
S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key."); S3FS_PRN_ERR("sse type is SSE-C, but there is no custom key.");
return false; return false;
} }
@ -1105,7 +1105,7 @@ bool S3fsCurl::LoadEnvSseCKeys(void)
while(getline(fullkeys, onekey, ':')){ while(getline(fullkeys, onekey, ':')){
S3fsCurl::PushbackSseKeys(onekey); S3fsCurl::PushbackSseKeys(onekey);
} }
if(0 == S3fsCurl::sseckeys.size()){ if(S3fsCurl::sseckeys.empty()){
S3FS_PRN_ERR("There is no SSE Key in environment(AWSSSECKEYS=%s).", envkeys); S3FS_PRN_ERR("There is no SSE Key in environment(AWSSSECKEYS=%s).", envkeys);
return false; return false;
} }
@ -1566,7 +1566,7 @@ bool S3fsCurl::SetIAMCredentials(const char* response)
bool S3fsCurl::CheckIAMCredentialUpdate(void) bool S3fsCurl::CheckIAMCredentialUpdate(void)
{ {
if(0 == S3fsCurl::IAM_role.size() && !S3fsCurl::is_ecs && !S3fsCurl::is_ibm_iam_auth){ if(S3fsCurl::IAM_role.empty() && !S3fsCurl::is_ecs && !S3fsCurl::is_ibm_iam_auth){
return true; return true;
} }
if(time(NULL) + IAM_EXPIRE_MERGIN <= S3fsCurl::AWSAccessTokenExpire){ if(time(NULL) + IAM_EXPIRE_MERGIN <= S3fsCurl::AWSAccessTokenExpire){
@ -1714,7 +1714,7 @@ bool S3fsCurl::ResetHandle(void)
if(0 == S3fsCurl::ssl_verify_hostname){ if(0 == S3fsCurl::ssl_verify_hostname){
curl_easy_setopt(hCurl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(hCurl, CURLOPT_SSL_VERIFYHOST, 0);
} }
if(S3fsCurl::curl_ca_bundle.size() != 0){ if(!S3fsCurl::curl_ca_bundle.empty()){
curl_easy_setopt(hCurl, CURLOPT_CAINFO, S3fsCurl::curl_ca_bundle.c_str()); curl_easy_setopt(hCurl, CURLOPT_CAINFO, S3fsCurl::curl_ca_bundle.c_str());
} }
} }
@ -2174,7 +2174,7 @@ int S3fsCurl::RequestPerform(void)
// try to locate cert, if successful, then set the // try to locate cert, if successful, then set the
// option and continue // option and continue
if(0 == S3fsCurl::curl_ca_bundle.size()){ if(S3fsCurl::curl_ca_bundle.empty()){
if(!S3fsCurl::LocateBundle()){ if(!S3fsCurl::LocateBundle()){
S3FS_PRN_ERR("could not get CURL_CA_BUNDLE."); S3FS_PRN_ERR("could not get CURL_CA_BUNDLE.");
return -EIO; return -EIO;
@ -2252,7 +2252,7 @@ string S3fsCurl::CalcSignatureV2(const string& method, const string& strMD5, con
string Signature; string Signature;
string StringToSign; string StringToSign;
if(0 < S3fsCurl::IAM_role.size() || S3fsCurl::is_ecs){ if(!S3fsCurl::IAM_role.empty() || S3fsCurl::is_ecs){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-security-token", S3fsCurl::AWSAccessToken.c_str()); requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-security-token", S3fsCurl::AWSAccessToken.c_str());
} }
@ -2290,7 +2290,7 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri
string Signature, StringCQ, StringToSign; string Signature, StringCQ, StringToSign;
string uriencode; string uriencode;
if(0 < S3fsCurl::IAM_role.size() || S3fsCurl::is_ecs){ if(!S3fsCurl::IAM_role.empty() || S3fsCurl::is_ecs){
requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-security-token", S3fsCurl::AWSAccessToken.c_str()); requestHeaders = curl_slist_sort_insert(requestHeaders, "x-amz-security-token", S3fsCurl::AWSAccessToken.c_str());
} }
@ -2543,7 +2543,7 @@ int S3fsCurl::GetIAMCredentials(void)
if (!S3fsCurl::is_ecs && !S3fsCurl::is_ibm_iam_auth) { if (!S3fsCurl::is_ecs && !S3fsCurl::is_ibm_iam_auth) {
S3FS_PRN_INFO3("[IAM role=%s]", S3fsCurl::IAM_role.c_str()); S3FS_PRN_INFO3("[IAM role=%s]", S3fsCurl::IAM_role.c_str());
if(0 == S3fsCurl::IAM_role.size()) { if(S3fsCurl::IAM_role.empty()) {
S3FS_PRN_ERR("IAM role name is empty."); S3FS_PRN_ERR("IAM role name is empty.");
return -EIO; return -EIO;
} }

View File

@ -176,7 +176,7 @@ bool CacheFileStat::SetPath(const char* tpath, bool is_open)
bool CacheFileStat::Open(void) bool CacheFileStat::Open(void)
{ {
if(0 == path.size()){ if(path.empty()){
return false; return false;
} }
if(-1 != fd){ if(-1 != fd){
@ -665,7 +665,7 @@ void FdEntity::Clear(void)
AutoLock auto_lock(&fdent_lock); AutoLock auto_lock(&fdent_lock);
if(-1 != fd){ if(-1 != fd){
if(0 != cachepath.size()){ if(!cachepath.empty()){
CacheFileStat cfstat(path.c_str()); CacheFileStat cfstat(path.c_str());
if(!pagelist.Serialize(cfstat, true)){ if(!pagelist.Serialize(cfstat, true)){
S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str()); S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str());
@ -702,7 +702,7 @@ void FdEntity::Close(void)
refcnt--; refcnt--;
} }
if(0 == refcnt){ if(0 == refcnt){
if(0 != cachepath.size()){ if(!cachepath.empty()){
CacheFileStat cfstat(path.c_str()); CacheFileStat cfstat(path.c_str());
if(!pagelist.Serialize(cfstat, true)){ if(!pagelist.Serialize(cfstat, true)){
S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str()); S3FS_PRN_WARN("failed to save cache stat file(%s).", path.c_str());
@ -834,7 +834,7 @@ int FdEntity::Open(headers_t* pmeta, ssize_t size, time_t time, bool no_fd_lock_
bool need_save_csf = false; // need to save(reset) cache stat file bool need_save_csf = false; // need to save(reset) cache stat file
bool is_truncate = false; // need to truncate bool is_truncate = false; // need to truncate
if(0 != cachepath.size()){ if(!cachepath.empty()){
// using cache // using cache
// open cache and cache stat file, load page info. // open cache and cache stat file, load page info.
@ -1039,7 +1039,7 @@ int FdEntity::SetMtime(time_t time)
S3FS_PRN_ERR("futimes failed. errno(%d)", errno); S3FS_PRN_ERR("futimes failed. errno(%d)", errno);
return -errno; return -errno;
} }
}else if(0 < cachepath.size()){ }else if(!cachepath.empty()){
// not opened file yet. // not opened file yet.
struct utimbuf n_mtime; struct utimbuf n_mtime;
n_mtime.modtime = time; n_mtime.modtime = time;
@ -1237,7 +1237,7 @@ int FdEntity::NoCacheLoadAndPost(off_t start, size_t size)
// [NOTE] // [NOTE]
// This method calling means that the cache file is never used no more. // This method calling means that the cache file is never used no more.
// //
if(0 != cachepath.size()){ if(!cachepath.empty()){
// remove cache files(and cache stat file) // remove cache files(and cache stat file)
FdManager::DeleteCacheFile(path.c_str()); FdManager::DeleteCacheFile(path.c_str());
// cache file path does not use no more. // cache file path does not use no more.
@ -1826,7 +1826,7 @@ bool FdManager::SetCacheDir(const char* dir)
bool FdManager::DeleteCacheDirectory(void) bool FdManager::DeleteCacheDirectory(void)
{ {
if(0 == FdManager::cache_dir.size()){ if(FdManager::cache_dir.empty()){
return true; return true;
} }
string cache_path; string cache_path;
@ -1843,7 +1843,7 @@ int FdManager::DeleteCacheFile(const char* path)
if(!path){ if(!path){
return -EIO; return -EIO;
} }
if(0 == FdManager::cache_dir.size()){ if(FdManager::cache_dir.empty()){
return 0; return 0;
} }
string cache_path; string cache_path;
@ -1876,7 +1876,7 @@ int FdManager::DeleteCacheFile(const char* path)
bool FdManager::MakeCachePath(const char* path, string& cache_path, bool is_create_dir, bool is_mirror_path) bool FdManager::MakeCachePath(const char* path, string& cache_path, bool is_create_dir, bool is_mirror_path)
{ {
if(0 == FdManager::cache_dir.size()){ if(FdManager::cache_dir.empty()){
cache_path = ""; cache_path = "";
return true; return true;
} }
@ -1908,7 +1908,7 @@ bool FdManager::MakeCachePath(const char* path, string& cache_path, bool is_crea
bool FdManager::CheckCacheTopDir(void) bool FdManager::CheckCacheTopDir(void)
{ {
if(0 == FdManager::cache_dir.size()){ if(FdManager::cache_dir.empty()){
return true; return true;
} }
string toppath(FdManager::cache_dir + "/" + bucket); string toppath(FdManager::cache_dir + "/" + bucket);
@ -1938,7 +1938,7 @@ bool FdManager::CheckCacheDirExist(void)
if(!FdManager::check_cache_dir_exist){ if(!FdManager::check_cache_dir_exist){
return true; return true;
} }
if(0 == FdManager::cache_dir.size()){ if(FdManager::cache_dir.empty()){
return true; return true;
} }
// check the directory // check the directory
@ -1965,7 +1965,7 @@ uint64_t FdManager::GetFreeDiskSpace(const char* path)
{ {
struct statvfs vfsbuf; struct statvfs vfsbuf;
string ctoppath; string ctoppath;
if(0 < FdManager::cache_dir.size()){ if(!FdManager::cache_dir.empty()){
ctoppath = FdManager::cache_dir + "/"; ctoppath = FdManager::cache_dir + "/";
ctoppath = get_exist_directory_path(ctoppath); // existed directory ctoppath = get_exist_directory_path(ctoppath); // existed directory
if(ctoppath != "/"){ if(ctoppath != "/"){
@ -2107,7 +2107,7 @@ FdEntity* FdManager::Open(const char* path, headers_t* pmeta, ssize_t size, time
// make new obj // make new obj
ent = new FdEntity(path, cache_path.c_str()); ent = new FdEntity(path, cache_path.c_str());
if(0 < cache_path.size()){ if(!cache_path.empty()){
// using cache // using cache
fent[string(path)] = ent; fent[string(path)] = ent;
}else{ }else{

View File

@ -706,7 +706,7 @@ static int check_parent_object_access(const char* path, int mask)
return 0; return 0;
} }
if(X_OK == (mask & X_OK)){ if(X_OK == (mask & X_OK)){
for(parent = mydirname(path); 0 < parent.size(); parent = mydirname(parent)){ for(parent = mydirname(path); !parent.empty(); parent = mydirname(parent)){
if(parent == "."){ if(parent == "."){
parent = "/"; parent = "/";
} }
@ -2513,7 +2513,7 @@ static int list_bucket(const char* path, S3ObjList& head, const char* delimiter,
while(truncated){ while(truncated){
string each_query = query_delimiter; string each_query = query_delimiter;
if(next_marker != ""){ if(!next_marker.empty()){
each_query += "marker=" + urlEncode(next_marker) + "&"; each_query += "marker=" + urlEncode(next_marker) + "&";
next_marker = ""; next_marker = "";
} }
@ -2679,7 +2679,7 @@ static bool GetXmlNsUrl(xmlDocPtr doc, string& nsurl)
} }
} }
} }
if(0 < strNs.size()){ if(!strNs.empty()){
nsurl = strNs; nsurl = strNs;
result = true; result = true;
} }
@ -3828,7 +3828,7 @@ static int s3fs_check_service(void)
s3fscurl.DestroyCurlHandle(); s3fscurl.DestroyCurlHandle();
// make sure remote mountpath exists and is a directory // make sure remote mountpath exists and is a directory
if(mount_prefix.size() > 0){ if(!mount_prefix.empty()){
if(remote_mountpath_exists(mount_prefix.c_str()) != 0){ if(remote_mountpath_exists(mount_prefix.c_str()) != 0){
S3FS_PRN_CRIT("remote mountpath %s not found.", mount_prefix.c_str()); S3FS_PRN_CRIT("remote mountpath %s not found.", mount_prefix.c_str());
return EXIT_FAILURE; return EXIT_FAILURE;
@ -3871,7 +3871,7 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
// read each line // read each line
while(getline(PF, line)){ while(getline(PF, line)){
line = trim(line); line = trim(line);
if(0 == line.size()){ if(line.empty()){
continue; continue;
} }
if('#' == line[0]){ if('#' == line[0]){
@ -3932,7 +3932,7 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
secret = trim(iter->substr(first_pos + 1, string::npos)); secret = trim(iter->substr(first_pos + 1, string::npos));
} }
if(resmap.end() != resmap.find(bucketname)){ if(resmap.end() != resmap.find(bucketname)){
S3FS_PRN_EXIT("there are multiple entries for the same bucket(%s) in the passwd file.", ("" == bucketname ? "default" : bucketname.c_str())); S3FS_PRN_EXIT("there are multiple entries for the same bucket(%s) in the passwd file.", (bucketname.empty() ? "default" : bucketname.c_str()));
return -1; return -1;
} }
kv.clear(); kv.clear();
@ -4038,7 +4038,7 @@ static int read_aws_credentials_file(const std::string &filename)
string line; string line;
while(getline(PF, line)){ while(getline(PF, line)){
line = trim(line); line = trim(line);
if(0 == line.size()){ if(line.empty()){
continue; continue;
} }
if('#' == line[0]){ if('#' == line[0]){
@ -4129,7 +4129,7 @@ static int read_passwd_file(void)
} }
string bucket_key = allbucket_fields_type; string bucket_key = allbucket_fields_type;
if(0 < bucket.size() && bucketmap.end() != bucketmap.find(bucket)){ if(!bucket.empty() && bucketmap.end() != bucketmap.find(bucket)){
bucket_key = bucket; bucket_key = bucket;
} }
if(bucketmap.end() == bucketmap.find(bucket_key)){ if(bucketmap.end() == bucketmap.find(bucket_key)){
@ -4183,7 +4183,7 @@ static int get_access_keys(void)
} }
// 2 - was specified on the command line // 2 - was specified on the command line
if(passwd_file.size() > 0){ if(!passwd_file.empty()){
ifstream PF(passwd_file.c_str()); ifstream PF(passwd_file.c_str());
if(PF.good()){ if(PF.good()){
PF.close(); PF.close();
@ -4215,7 +4215,7 @@ static int get_access_keys(void)
AWS_CREDENTIAL_FILE = getenv("AWS_CREDENTIAL_FILE"); AWS_CREDENTIAL_FILE = getenv("AWS_CREDENTIAL_FILE");
if(AWS_CREDENTIAL_FILE != NULL){ if(AWS_CREDENTIAL_FILE != NULL){
passwd_file.assign(AWS_CREDENTIAL_FILE); passwd_file.assign(AWS_CREDENTIAL_FILE);
if(passwd_file.size() > 0){ if(!passwd_file.empty()){
ifstream PF(passwd_file.c_str()); ifstream PF(passwd_file.c_str());
if(PF.good()){ if(PF.good()){
PF.close(); PF.close();
@ -4340,7 +4340,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
int ret; int ret;
if(key == FUSE_OPT_KEY_NONOPT){ if(key == FUSE_OPT_KEY_NONOPT){
// the first NONOPT option is the bucket name // the first NONOPT option is the bucket name
if(bucket.size() == 0){ if(bucket.empty()){
if ((ret = set_bucket(arg))){ if ((ret = set_bucket(arg))){
return ret; return ret;
} }
@ -4351,7 +4351,7 @@ static int my_fuse_opt_proc(void* data, const char* arg, int key, struct fuse_ar
} }
// the second NONOPT option is the mountpoint(not utility mode) // the second NONOPT option is the mountpoint(not utility mode)
if(0 == mountpoint.size() && 0 == utility_mode){ if(mountpoint.empty() && 0 == utility_mode){
// save the mountpoint and do some basic error checking // save the mountpoint and do some basic error checking
mountpoint = arg; mountpoint = arg;
struct stat stbuf; struct stat stbuf;
@ -5054,7 +5054,7 @@ int main(int argc, char* argv[])
} }
// The first plain argument is the bucket // The first plain argument is the bucket
if(bucket.size() == 0){ if(bucket.empty()){
S3FS_PRN_EXIT("missing BUCKET argument."); S3FS_PRN_EXIT("missing BUCKET argument.");
show_usage(); show_usage();
S3fsCurl::DestroyS3fsCurl(); S3fsCurl::DestroyS3fsCurl();
@ -5091,7 +5091,7 @@ int main(int argc, char* argv[])
// readable, non-empty directory, this checks determines // readable, non-empty directory, this checks determines
// if the mountpoint option was ever supplied // if the mountpoint option was ever supplied
if(utility_mode == 0){ if(utility_mode == 0){
if(mountpoint.size() == 0){ if(mountpoint.empty()){
S3FS_PRN_EXIT("missing MOUNTPOINT argument."); S3FS_PRN_EXIT("missing MOUNTPOINT argument.");
show_usage(); show_usage();
S3fsCurl::DestroyS3fsCurl(); S3fsCurl::DestroyS3fsCurl();
@ -5107,7 +5107,7 @@ int main(int argc, char* argv[])
s3fs_destroy_global_ssl(); s3fs_destroy_global_ssl();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(passwd_file.size() > 0 && S3fsCurl::IsSetAccessKeys()){ if(!passwd_file.empty() && S3fsCurl::IsSetAccessKeys()){
S3FS_PRN_EXIT("specifying both passwd_file and the access keys options is invalid."); S3FS_PRN_EXIT("specifying both passwd_file and the access keys options is invalid.");
S3fsCurl::DestroyS3fsCurl(); S3fsCurl::DestroyS3fsCurl();
s3fs_destroy_global_ssl(); s3fs_destroy_global_ssl();