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