diff --git a/src/cache.cpp b/src/cache.cpp index 593760a..d538a1e 100644 --- a/src/cache.cpp +++ b/src/cache.cpp @@ -449,7 +449,7 @@ bool StatCache::UpdateMetaStats(const std::string& key, headers_t& meta) SetStatCacheTime(ent->cache_date); // Update only mode - ent->stbuf.st_mode = get_mode(meta); + ent->stbuf.st_mode = get_mode(meta, key); return true; } diff --git a/src/metaheader.cpp b/src/metaheader.cpp index d0c28b5..fc6f630 100644 --- a/src/metaheader.cpp +++ b/src/metaheader.cpp @@ -125,7 +125,7 @@ mode_t get_mode(const char *s, int base) return static_cast(cvt_strtoofft(s, base)); } -mode_t get_mode(const headers_t& meta, const char* path, bool checkdir, bool forcedir) +mode_t get_mode(const headers_t& meta, const std::string& strpath, bool checkdir, bool forcedir) { mode_t mode = 0; bool isS3sync = false; @@ -141,7 +141,7 @@ mode_t get_mode(const headers_t& meta, const char* path, bool checkdir, bool for }else{ // If another tool creates an object without permissions, default to owner // read-write and group readable. - mode = path[strlen(path) - 1] == '/' ? 0750 : 0640; + mode = (!strpath.empty() && '/' == *strpath.rbegin()) ? 0750 : 0640; } // Checking the bitmask, if the last 3 bits are all zero then process as a regular @@ -163,7 +163,7 @@ mode_t get_mode(const headers_t& meta, const char* path, bool checkdir, bool for if(strConType == "application/x-directory" || strConType == "httpd/unix-directory"){ // Nextcloud uses this MIME type for directory objects when mounting bucket as external Storage mode |= S_IFDIR; - }else if(path && 0 < strlen(path) && '/' == path[strlen(path) - 1]){ + }else if(!strpath.empty() && '/' == *strpath.rbegin()){ if(strConType == "binary/octet-stream" || strConType == "application/octet-stream"){ mode |= S_IFDIR; }else{ diff --git a/src/metaheader.h b/src/metaheader.h index 5f78a42..44dd8a5 100644 --- a/src/metaheader.h +++ b/src/metaheader.h @@ -46,7 +46,7 @@ struct timespec get_atime(const headers_t& meta, bool overcheck = true); off_t get_size(const char *s); off_t get_size(const headers_t& meta); mode_t get_mode(const char *s, int base = 0); -mode_t get_mode(const headers_t& meta, const char* path = NULL, bool checkdir = false, bool forcedir = false); +mode_t get_mode(const headers_t& meta, const std::string& strpath, bool checkdir = false, bool forcedir = false); uid_t get_uid(const char *s); uid_t get_uid(const headers_t& meta); gid_t get_gid(const char *s);