From 51b3183cba060ef8f5b243abc0bf458b5cae36c2 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Fri, 5 May 2017 09:51:30 +0000 Subject: [PATCH 1/2] Refactored the check_object_access function --- src/s3fs.cpp | 80 ++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 8286edc..14990be 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -421,7 +421,8 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t } // Check cache. - strpath = path; + pisforce = (NULL != pisforce ? pisforce : &forcedir); + strpath = path; if(overcheck && string::npos != (Pos = strpath.find("_$folder$", 0))){ strpath = strpath.substr(0, Pos); strpath += "/"; @@ -443,57 +444,50 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); s3fscurl.DestroyCurlHandle(); - // overcheck - if(overcheck && 0 != result){ - if('/' != strpath[strpath.length() - 1] && string::npos == strpath.find("_$folder$", 0)){ - // path is "object", check "object/" for overcheck - strpath += "/"; - result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); - s3fscurl.DestroyCurlHandle(); - } - if(0 != result){ - // not found "object/", check "_$folder$" - strpath = path; - if(string::npos == strpath.find("_$folder$", 0)){ - if('/' == strpath[strpath.length() - 1]){ - strpath = strpath.substr(0, strpath.length() - 1); - } - strpath += "_$folder$"; + // if not found target path object, do over checking + if(0 != result){ + if(overcheck){ + if('/' != strpath[strpath.length() - 1]){ + // now path is "object", do check "object/" for over checking + strpath += "/"; result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); s3fscurl.DestroyCurlHandle(); } - } - if(0 != result){ - // not found "object/" and "object_$folder$", check no dir object. - strpath = path; - if(string::npos == strpath.find("_$folder$", 0)){ - if('/' == strpath[strpath.length() - 1]){ - strpath = strpath.substr(0, strpath.length() - 1); - } - if(-ENOTEMPTY == directory_empty(strpath.c_str())){ - // found "no dir object". - strpath += "/"; - forcedir = true; - if(pisforce){ - (*pisforce) = true; + if(0 != result){ + // now path is "object/", do check "object_$folder$" for over checking + strpath = strpath.substr(0, strpath.length() - 1); + strpath += "_$folder$"; + result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); + s3fscurl.DestroyCurlHandle(); + + if(0 != result){ + // cut "_$folder$" for over checking "no dir object" after here + if(string::npos != (Pos = strpath.find("_$folder$", 0))){ + strpath = strpath.substr(0, Pos); } - result = 0; } } } + if(0 != result && string::npos == strpath.find("_$folder$", 0)){ + // now path is "object" or "object/", do check "no dir object" which is not object but has only children. + if('/' == strpath[strpath.length() - 1]){ + strpath = strpath.substr(0, strpath.length() - 1); + } + if(-ENOTEMPTY == directory_empty(strpath.c_str())){ + // found "no dir object". + strpath += "/"; + *pisforce = true; + result = 0; + } + } }else{ - // found "path" object. - if('/' != strpath[strpath.length() - 1]){ + if('/' != strpath[strpath.length() - 1] && string::npos == strpath.find("_$folder$", 0) && is_need_check_obj_detail(*pheader)){ // check a case of that "object" does not have attribute and "object" is possible to be directory. - if(is_need_check_obj_detail(*pheader)){ - if(-ENOTEMPTY == directory_empty(strpath.c_str())){ - strpath += "/"; - forcedir = true; - if(pisforce){ - (*pisforce) = true; - } - result = 0; - } + if(-ENOTEMPTY == directory_empty(strpath.c_str())){ + // found "no dir object". + strpath += "/"; + *pisforce = true; + result = 0; } } } From 864e20e1f2e12ef7b366ef10f86717ff69db77f0 Mon Sep 17 00:00:00 2001 From: Takeshi Nakatani Date: Fri, 5 May 2017 10:02:21 +0000 Subject: [PATCH 2/2] Refactored the get_object_attribute function --- src/s3fs.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/s3fs.cpp b/src/s3fs.cpp index 14990be..822fe36 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -421,15 +421,13 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t } // Check cache. - pisforce = (NULL != pisforce ? pisforce : &forcedir); - strpath = path; + pisforce = (NULL != pisforce ? pisforce : &forcedir); + (*pisforce) = false; + strpath = path; if(overcheck && string::npos != (Pos = strpath.find("_$folder$", 0))){ strpath = strpath.substr(0, Pos); strpath += "/"; } - if(pisforce){ - (*pisforce) = false; - } if(StatCache::getStatCacheData()->GetStat(strpath, pstat, pheader, overcheck, pisforce)){ StatCache::getStatCacheData()->ChangeNoTruncateFlag(strpath, add_no_truncate_cache); return 0;