mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2025-01-24 06:18:25 +00:00
Address cppcheck 1.86 errors
Lifetime, shadowing, and unused variables. Found via the Travis macOS builder.
This commit is contained in:
parent
d9e89deef6
commit
a2f8ac535e
@ -255,10 +255,10 @@ bool StatCache::GetStat(string& key, struct stat* pst, headers_t* meta, bool ove
|
||||
string stretag;
|
||||
if(petag){
|
||||
// find & check ETag
|
||||
for(headers_t::iterator iter = ent->meta.begin(); iter != ent->meta.end(); ++iter){
|
||||
string tag = lower(iter->first);
|
||||
for(headers_t::iterator hiter = ent->meta.begin(); hiter != ent->meta.end(); ++hiter){
|
||||
string tag = lower(hiter->first);
|
||||
if(tag == "etag"){
|
||||
stretag = iter->second;
|
||||
stretag = hiter->second;
|
||||
if('\0' != petag[0] && 0 != strcmp(petag, stretag.c_str())){
|
||||
is_delete_cache = true;
|
||||
}
|
||||
|
@ -158,6 +158,7 @@ typedef std::map<std::string, PXATTRVAL> xattrs_t;
|
||||
//
|
||||
// Global variables
|
||||
//
|
||||
// TODO: namespace these
|
||||
extern bool foreground;
|
||||
extern bool nomultipart;
|
||||
extern bool pathrequeststyle;
|
||||
|
36
src/curl.cpp
36
src/curl.cpp
@ -103,21 +103,21 @@ static string url_to_host(const std::string &url)
|
||||
|
||||
static const string http = "http://";
|
||||
static const string https = "https://";
|
||||
std::string host;
|
||||
std::string hostname;
|
||||
|
||||
if (url.compare(0, http.size(), http) == 0) {
|
||||
host = url.substr(http.size());
|
||||
hostname = url.substr(http.size());
|
||||
} else if (url.compare(0, https.size(), https) == 0) {
|
||||
host = url.substr(https.size());
|
||||
hostname = url.substr(https.size());
|
||||
} else {
|
||||
assert(!"url does not begin with http:// or https://");
|
||||
}
|
||||
|
||||
size_t idx;
|
||||
if ((idx = host.find('/')) != string::npos) {
|
||||
return host.substr(0, idx);
|
||||
if ((idx = hostname.find('/')) != string::npos) {
|
||||
return hostname.substr(0, idx);
|
||||
} else {
|
||||
return host;
|
||||
return hostname;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3904,24 +3904,23 @@ int S3fsMultiCurl::MultiPerform(void)
|
||||
bool success = true;
|
||||
bool isMultiHead = false;
|
||||
Semaphore sem(S3fsCurl::max_parallel_cnt);
|
||||
int rc;
|
||||
|
||||
for(s3fscurlmap_t::iterator iter = cMap_req.begin(); iter != cMap_req.end(); ++iter) {
|
||||
pthread_t thread;
|
||||
S3fsCurl* s3fscurl = (*iter).second;
|
||||
int rc;
|
||||
s3fscurl->sem = &sem;
|
||||
|
||||
sem.wait();
|
||||
|
||||
#ifndef __APPLE__
|
||||
// macOS does not support pthread_tryjoin_np so we do not eagerly reap threads
|
||||
for (std::vector<pthread_t>::iterator iter = threads.begin(); iter != threads.end(); ++iter) {
|
||||
for (std::vector<pthread_t>::iterator titer = threads.begin(); titer != threads.end(); ++titer) {
|
||||
void* retval;
|
||||
int rc;
|
||||
|
||||
rc = pthread_tryjoin_np(*iter, &retval);
|
||||
rc = pthread_tryjoin_np(*titer, &retval);
|
||||
if (rc == 0) {
|
||||
iter = threads.erase(iter);
|
||||
titer = threads.erase(titer);
|
||||
int int_retval = (int)(intptr_t)(retval);
|
||||
if (int_retval && !(int_retval == -ENOENT && isMultiHead)) {
|
||||
S3FS_PRN_WARN("thread failed - rc(%d)", int_retval);
|
||||
@ -3930,7 +3929,7 @@ int S3fsMultiCurl::MultiPerform(void)
|
||||
} else if (rc == EBUSY) {
|
||||
continue;
|
||||
} else {
|
||||
iter = threads.erase(iter);
|
||||
titer = threads.erase(titer);
|
||||
success = false;
|
||||
S3FS_PRN_ERR("failed pthread_tryjoin_np - rc(%d)", rc);
|
||||
}
|
||||
@ -3960,11 +3959,10 @@ int S3fsMultiCurl::MultiPerform(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
for (std::vector<pthread_t>::iterator iter = threads.begin(); iter != threads.end(); ++iter) {
|
||||
for (std::vector<pthread_t>::iterator titer = threads.begin(); titer != threads.end(); ++titer) {
|
||||
void* retval;
|
||||
int rc;
|
||||
|
||||
rc = pthread_join(*iter, &retval);
|
||||
rc = pthread_join(*titer, &retval);
|
||||
if (rc) {
|
||||
success = false;
|
||||
S3FS_PRN_ERR("failed pthread_join - rc(%d)", rc);
|
||||
@ -4308,7 +4306,7 @@ string prepare_url(const char* url)
|
||||
S3FS_PRN_INFO3("URL is %s", url);
|
||||
|
||||
string uri;
|
||||
string host;
|
||||
string hostname;
|
||||
string path;
|
||||
string url_str = string(url);
|
||||
string token = string("/") + bucket;
|
||||
@ -4324,10 +4322,10 @@ string prepare_url(const char* url)
|
||||
uri = url_str.substr(0, uri_length);
|
||||
|
||||
if(!pathrequeststyle){
|
||||
host = bucket + "." + url_str.substr(uri_length, bucket_pos - uri_length).c_str();
|
||||
hostname = bucket + "." + url_str.substr(uri_length, bucket_pos - uri_length).c_str();
|
||||
path = url_str.substr((bucket_pos + bucket_length));
|
||||
}else{
|
||||
host = url_str.substr(uri_length, bucket_pos - uri_length).c_str();
|
||||
hostname = url_str.substr(uri_length, bucket_pos - uri_length).c_str();
|
||||
string part = url_str.substr((bucket_pos + bucket_length));
|
||||
if('/' != part[0]){
|
||||
part = "/" + part;
|
||||
@ -4335,7 +4333,7 @@ string prepare_url(const char* url)
|
||||
path = "/" + bucket + part;
|
||||
}
|
||||
|
||||
url_str = uri + host + path;
|
||||
url_str = uri + hostname + path;
|
||||
|
||||
S3FS_PRN_INFO3("URL changed is %s", url_str.c_str());
|
||||
|
||||
|
@ -1808,11 +1808,11 @@ bool FdManager::DeleteCacheDirectory(void)
|
||||
if(0 == FdManager::cache_dir.size()){
|
||||
return true;
|
||||
}
|
||||
string cache_dir;
|
||||
if(!FdManager::MakeCachePath(NULL, cache_dir, false)){
|
||||
string cache_path;
|
||||
if(!FdManager::MakeCachePath(NULL, cache_path, false)){
|
||||
return false;
|
||||
}
|
||||
return delete_files_in_dir(cache_dir.c_str(), true);
|
||||
return delete_files_in_dir(cache_path.c_str(), true);
|
||||
}
|
||||
|
||||
int FdManager::DeleteCacheFile(const char* path)
|
||||
|
@ -96,7 +96,6 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
|
||||
PK11SlotInfo* Slot;
|
||||
PK11SymKey* pKey;
|
||||
PK11Context* Context;
|
||||
SECStatus SecStatus;
|
||||
unsigned char tmpdigest[64];
|
||||
SECItem KeySecItem = {siBuffer, reinterpret_cast<unsigned char*>(const_cast<void*>(key)), static_cast<unsigned int>(keylen)};
|
||||
SECItem NullSecItem = {siBuffer, NULL, 0};
|
||||
@ -115,9 +114,9 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d
|
||||
}
|
||||
|
||||
*digestlen = 0;
|
||||
if(SECSuccess != (SecStatus = PK11_DigestBegin(Context)) ||
|
||||
SECSuccess != (SecStatus = PK11_DigestOp(Context, data, datalen)) ||
|
||||
SECSuccess != (SecStatus = PK11_DigestFinal(Context, tmpdigest, digestlen, sizeof(tmpdigest))) )
|
||||
if(SECSuccess != PK11_DigestBegin(Context) ||
|
||||
SECSuccess != PK11_DigestOp(Context, data, datalen) ||
|
||||
SECSuccess != PK11_DigestFinal(Context, tmpdigest, digestlen, sizeof(tmpdigest)) )
|
||||
{
|
||||
PK11_DestroyContext(Context, PR_TRUE);
|
||||
PK11_FreeSymKey(pKey);
|
||||
|
26
src/s3fs.cpp
26
src/s3fs.cpp
@ -2915,7 +2915,7 @@ static size_t parse_xattrs(const std::string& strxattrs, xattrs_t& xattrs)
|
||||
// get from "{" to "}"
|
||||
string restxattrs;
|
||||
{
|
||||
size_t startpos = string::npos;
|
||||
size_t startpos;
|
||||
size_t endpos = string::npos;
|
||||
if(string::npos != (startpos = jsonxattrs.find_first_of("{"))){
|
||||
endpos = jsonxattrs.find_last_of("}");
|
||||
@ -3223,9 +3223,9 @@ 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 iter = xattrs.begin(); iter != xattrs.end(); ++iter){
|
||||
if(0 < iter->first.length()){
|
||||
total += iter->first.length() + 1;
|
||||
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
|
||||
if(0 < xiter->first.length()){
|
||||
total += xiter->first.length() + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3246,9 +3246,9 @@ static int s3fs_listxattr(const char* path, char* list, size_t size)
|
||||
|
||||
// copy to list
|
||||
char* setpos = list;
|
||||
for(xattrs_t::const_iterator iter = xattrs.begin(); iter != xattrs.end(); ++iter){
|
||||
if(0 < iter->first.length()){
|
||||
strcpy(setpos, iter->first.c_str());
|
||||
for(xattrs_t::const_iterator xiter = xattrs.begin(); xiter != xattrs.end(); ++xiter){
|
||||
if(0 < xiter->first.length()){
|
||||
strcpy(setpos, xiter->first.c_str());
|
||||
setpos = &setpos[strlen(setpos) + 1];
|
||||
}
|
||||
}
|
||||
@ -3887,28 +3887,28 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
|
||||
if(first_pos == string::npos){
|
||||
continue;
|
||||
}
|
||||
string bucket;
|
||||
string bucketname;
|
||||
string accesskey;
|
||||
string secret;
|
||||
if(first_pos != last_pos){
|
||||
// formatted by "bucket:accesskey:secretkey"
|
||||
bucket = trim(iter->substr(0, first_pos));
|
||||
bucketname = trim(iter->substr(0, first_pos));
|
||||
accesskey = trim(iter->substr(first_pos + 1, last_pos - first_pos - 1));
|
||||
secret = trim(iter->substr(last_pos + 1, string::npos));
|
||||
}else{
|
||||
// formatted by "accesskey:secretkey"
|
||||
bucket = allbucket_fields_type;
|
||||
bucketname = allbucket_fields_type;
|
||||
accesskey = trim(iter->substr(0, first_pos));
|
||||
secret = trim(iter->substr(first_pos + 1, string::npos));
|
||||
}
|
||||
if(resmap.end() != resmap.find(bucket)){
|
||||
S3FS_PRN_EXIT("there are multiple entries for the same bucket(%s) in the passwd file.", ("" == bucket ? "default" : bucket.c_str()));
|
||||
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()));
|
||||
return -1;
|
||||
}
|
||||
kv.clear();
|
||||
kv[string(aws_accesskeyid)] = accesskey;
|
||||
kv[string(aws_secretkey)] = secret;
|
||||
resmap[bucket] = kv;
|
||||
resmap[bucketname] = kv;
|
||||
}
|
||||
return (resmap.empty() ? 0 : 1);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user