Make string constants read-only const (#1733)

This removes some global constructors.  Also use a consistent ALL_CAPS
style.
This commit is contained in:
Andrew Gaul 2021-08-03 00:10:27 +09:00 committed by GitHub
parent 34f89e5936
commit 18e9c62087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 38 deletions

View File

@ -40,8 +40,8 @@
//-------------------------------------------------------------------
// Symbols
//-------------------------------------------------------------------
static const std::string empty_payload_hash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
static const std::string empty_md5_base64_hash = "1B2M2Y8AsgTpgAmY7PhCfg==";
static const char EMPTY_PAYLOAD_HASH[] = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
static const char EMPTY_MD5_BASE64_HASH[] = "1B2M2Y8AsgTpgAmY7PhCfg==";
//-------------------------------------------------------------------
// Class S3fsCurl
@ -50,10 +50,10 @@ static const int MULTIPART_SIZE = 10 * 1024 * 1024;
static const int GET_OBJECT_RESPONSE_LIMIT = 1024;
static const int IAM_EXPIRE_MERGIN = 20 * 60; // update timing
static const std::string ECS_IAM_ENV_VAR = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
static const std::string IAMCRED_ACCESSKEYID = "AccessKeyId";
static const std::string IAMCRED_SECRETACCESSKEY = "SecretAccessKey";
static const std::string IAMCRED_ROLEARN = "RoleArn";
static const char ECS_IAM_ENV_VAR[] = "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI";
static const char IAMCRED_ACCESSKEYID[] = "AccessKeyId";
static const char IAMCRED_SECRETACCESSKEY[] = "SecretAccessKey";
static const char IAMCRED_ROLEARN[] = "RoleArn";
// [NOTE] about default mime.types file
// If no mime.types file is specified in the mime option, s3fs
@ -2682,7 +2682,7 @@ void S3fsCurl::insertV4Headers()
std::string date8601;
get_date_sigv3(strdate, date8601);
std::string contentSHA256 = payload_hash.empty() ? empty_payload_hash : payload_hash;
std::string contentSHA256 = payload_hash.empty() ? EMPTY_PAYLOAD_HASH : payload_hash;
const std::string realpath = pathrequeststyle ? "/" + bucket + server_path : server_path;
//string canonical_headers, signed_headers;
@ -2836,9 +2836,9 @@ int S3fsCurl::GetIAMCredentials()
// url
if(is_ecs){
const char *env = std::getenv(ECS_IAM_ENV_VAR.c_str());
const char *env = std::getenv(ECS_IAM_ENV_VAR);
if(env == NULL){
S3FS_PRN_ERR("%s is not set.", ECS_IAM_ENV_VAR.c_str());
S3FS_PRN_ERR("%s is not set.", ECS_IAM_ENV_VAR);
return -EIO;
}
url = std::string(S3fsCurl::IAM_cred_url) + env;
@ -3232,7 +3232,7 @@ int S3fsCurl::PutRequest(const char* tpath, headers_t& meta, int fd)
return -EIO;
}
}else{
strMD5 = empty_md5_base64_hash;
strMD5 = EMPTY_MD5_BASE64_HASH;
}
requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", strMD5.c_str());
}

View File

@ -330,14 +330,14 @@ std::string url_to_host(const std::string &url)
{
S3FS_PRN_INFO3("url is %s", url.c_str());
static const std::string http = "http://";
static const std::string https = "https://";
static const char HTTP[] = "http://";
static const char HTTPS[] = "https://";
std::string hostname;
if (is_prefix(url.c_str(), http.c_str())) {
hostname = url.substr(http.size());
} else if (is_prefix(url.c_str(), https.c_str())) {
hostname = url.substr(https.size());
if (is_prefix(url.c_str(), HTTP)) {
hostname = url.substr(sizeof(HTTP) - 1);
} else if (is_prefix(url.c_str(), HTTPS)) {
hostname = url.substr(sizeof(HTTPS) - 1);
} else {
S3FS_PRN_EXIT("url does not begin with http:// or https://");
abort();

View File

@ -100,10 +100,10 @@ static off_t max_dirty_data = 5LL * 1024LL * 1024LL * 1024LL;
static bool use_wtf8 = false;
static off_t fake_diskfree_size = -1; // default is not set(-1)
static const std::string allbucket_fields_type; // special key for mapping(This name is absolutely not used as a bucket name)
static const std::string keyval_fields_type = "\t"; // special key for mapping(This name is absolutely not used as a bucket name)
static const std::string aws_accesskeyid = "AWSAccessKeyId";
static const std::string aws_secretkey = "AWSSecretKey";
static const char ALLBUCKET_FIELDS_TYPE[] = ""; // special key for mapping(This name is absolutely not used as a bucket name)
static const char KEYVAL_FIELDS_TYPE[] = "\t"; // special key for mapping(This name is absolutely not used as a bucket name)
static const char AWS_ACCESSKEYID[] = "AWSAccessKeyId";
static const char AWS_SECRETKEY[] = "AWSSecretKey";
//-------------------------------------------------------------------
// Global functions : prototype
@ -3682,7 +3682,7 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
kv[key] = val;
}
// set special key name
resmap[std::string(keyval_fields_type)] = kv;
resmap[KEYVAL_FIELDS_TYPE] = kv;
// read ':' type
for(iter = linelist.begin(); iter != linelist.end(); ++iter){
@ -3701,7 +3701,7 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
secret = trim(iter->substr(last_pos + 1, std::string::npos));
}else{
// formatted by "accesskey:secretkey"
bucketname = allbucket_fields_type;
bucketname = ALLBUCKET_FIELDS_TYPE;
accesskey = trim(iter->substr(0, first_pos));
secret = trim(iter->substr(first_pos + 1, std::string::npos));
}
@ -3710,8 +3710,8 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
return -1;
}
kv.clear();
kv[std::string(aws_accesskeyid)] = accesskey;
kv[std::string(aws_secretkey)] = secret;
kv[AWS_ACCESSKEYID] = accesskey;
kv[AWS_SECRETKEY] = secret;
resmap[bucketname] = kv;
}
return (resmap.empty() ? 0 : 1);
@ -3724,8 +3724,8 @@ static int parse_passwd_file(bucketkvmap_t& resmap)
//
static int check_for_aws_format(const kvmap_t& kvmap)
{
std::string str1(aws_accesskeyid);
std::string str2(aws_secretkey);
std::string str1(AWS_ACCESSKEYID);
std::string str2(AWS_SECRETKEY);
if(kvmap.empty()){
return 0;
@ -3909,7 +3909,7 @@ static int read_passwd_file()
//
// check key=value type format.
//
bucketkvmap_t::iterator it = bucketmap.find(keyval_fields_type);
bucketkvmap_t::iterator it = bucketmap.find(KEYVAL_FIELDS_TYPE);
if(bucketmap.end() != it){
// aws format
result = check_for_aws_format(it->second);
@ -3921,7 +3921,7 @@ static int read_passwd_file()
}
}
std::string bucket_key = allbucket_fields_type;
std::string bucket_key = ALLBUCKET_FIELDS_TYPE;
if(!bucket.empty() && bucketmap.end() != bucketmap.find(bucket)){
bucket_key = bucket;
}
@ -3931,8 +3931,8 @@ static int read_passwd_file()
return EXIT_FAILURE;
}
keyval = it->second;
kvmap_t::iterator aws_accesskeyid_it = keyval.find(aws_accesskeyid);
kvmap_t::iterator aws_secretkey_it = keyval.find(aws_secretkey);
kvmap_t::iterator aws_accesskeyid_it = keyval.find(AWS_ACCESSKEYID);
kvmap_t::iterator aws_secretkey_it = keyval.find(AWS_SECRETKEY);
if(keyval.end() == aws_accesskeyid_it || keyval.end() == aws_secretkey_it){
S3FS_PRN_EXIT("Not found access key/secret key in passwd file.");
return EXIT_FAILURE;

View File

@ -35,7 +35,7 @@
//-------------------------------------------------------------------
// Global variables
//-------------------------------------------------------------------
const std::string SPACES = " \t\r\n";
const char SPACES[] = " \t\r\n";
//-------------------------------------------------------------------
// Templates
@ -108,13 +108,13 @@ std::string lower(std::string s)
return s;
}
std::string trim_left(const std::string &s, const std::string &t /* = SPACES */)
std::string trim_left(const std::string &s, const char *t /* = SPACES */)
{
std::string d(s);
return d.erase(0, s.find_first_not_of(t));
}
std::string trim_right(const std::string &s, const std::string &t /* = SPACES */)
std::string trim_right(const std::string &s, const char *t /* = SPACES */)
{
std::string d(s);
std::string::size_type i(d.find_last_not_of(t));
@ -125,7 +125,7 @@ std::string trim_right(const std::string &s, const std::string &t /* = SPACES */
}
}
std::string trim(const std::string &s, const std::string &t /* = SPACES */)
std::string trim(const std::string &s, const char *t /* = SPACES */)
{
return trim_left(trim_right(s, t), t);
}

View File

@ -27,7 +27,7 @@
//-------------------------------------------------------------------
// Global variables
//-------------------------------------------------------------------
extern const std::string SPACES;
extern const char SPACES[];
//-------------------------------------------------------------------
// Inline functions
@ -68,9 +68,9 @@ off_t cvt_strtoofft(const char* str, int base);
//
// String Manipulation
//
std::string trim_left(const std::string &s, const std::string &t = SPACES);
std::string trim_right(const std::string &s, const std::string &t = SPACES);
std::string trim(const std::string &s, const std::string &t = SPACES);
std::string trim_left(const std::string &s, const char *t = SPACES);
std::string trim_right(const std::string &s, const char *t = SPACES);
std::string trim(const std::string &s, const char *t = SPACES);
std::string lower(std::string s);
//