Merge pull request #1 from ggtakec/test

Refactored the get_object_attribute function
This commit is contained in:
Takeshi Nakatani 2017-05-05 19:09:45 +09:00 committed by GitHub
commit 67685c3d49

View File

@ -421,14 +421,13 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t
} }
// Check cache. // Check cache.
pisforce = (NULL != pisforce ? pisforce : &forcedir);
(*pisforce) = false;
strpath = path; strpath = path;
if(overcheck && string::npos != (Pos = strpath.find("_$folder$", 0))){ if(overcheck && string::npos != (Pos = strpath.find("_$folder$", 0))){
strpath = strpath.substr(0, Pos); strpath = strpath.substr(0, Pos);
strpath += "/"; strpath += "/";
} }
if(pisforce){
(*pisforce) = false;
}
if(StatCache::getStatCacheData()->GetStat(strpath, pstat, pheader, overcheck, pisforce)){ if(StatCache::getStatCacheData()->GetStat(strpath, pstat, pheader, overcheck, pisforce)){
StatCache::getStatCacheData()->ChangeNoTruncateFlag(strpath, add_no_truncate_cache); StatCache::getStatCacheData()->ChangeNoTruncateFlag(strpath, add_no_truncate_cache);
return 0; return 0;
@ -443,60 +442,53 @@ static int get_object_attribute(const char* path, struct stat* pstbuf, headers_t
result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader));
s3fscurl.DestroyCurlHandle(); s3fscurl.DestroyCurlHandle();
// overcheck // if not found target path object, do over checking
if(overcheck && 0 != result){ if(0 != result){
if('/' != strpath[strpath.length() - 1] && string::npos == strpath.find("_$folder$", 0)){ if(overcheck){
// path is "object", check "object/" for overcheck if('/' != strpath[strpath.length() - 1]){
// now path is "object", do check "object/" for over checking
strpath += "/"; strpath += "/";
result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader));
s3fscurl.DestroyCurlHandle(); s3fscurl.DestroyCurlHandle();
} }
if(0 != result){ if(0 != result){
// not found "object/", check "_$folder$" // now path is "object/", do check "object_$folder$" for over checking
strpath = path;
if(string::npos == strpath.find("_$folder$", 0)){
if('/' == strpath[strpath.length() - 1]){
strpath = strpath.substr(0, strpath.length() - 1); strpath = strpath.substr(0, strpath.length() - 1);
}
strpath += "_$folder$"; strpath += "_$folder$";
result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader));
s3fscurl.DestroyCurlHandle(); s3fscurl.DestroyCurlHandle();
}
}
if(0 != result){ if(0 != result){
// not found "object/" and "object_$folder$", check no dir object. // cut "_$folder$" for over checking "no dir object" after here
strpath = path; if(string::npos != (Pos = strpath.find("_$folder$", 0))){
if(string::npos == strpath.find("_$folder$", 0)){ strpath = strpath.substr(0, Pos);
}
}
}
}
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]){ if('/' == strpath[strpath.length() - 1]){
strpath = strpath.substr(0, strpath.length() - 1); strpath = strpath.substr(0, strpath.length() - 1);
} }
if(-ENOTEMPTY == directory_empty(strpath.c_str())){ if(-ENOTEMPTY == directory_empty(strpath.c_str())){
// found "no dir object". // found "no dir object".
strpath += "/"; strpath += "/";
forcedir = true; *pisforce = true;
if(pisforce){
(*pisforce) = true;
}
result = 0; result = 0;
} }
} }
}
}else{ }else{
// found "path" object. if('/' != strpath[strpath.length() - 1] && string::npos == strpath.find("_$folder$", 0) && is_need_check_obj_detail(*pheader)){
if('/' != strpath[strpath.length() - 1]){
// check a case of that "object" does not have attribute and "object" is possible to be directory. // 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())){ if(-ENOTEMPTY == directory_empty(strpath.c_str())){
// found "no dir object".
strpath += "/"; strpath += "/";
forcedir = true; *pisforce = true;
if(pisforce){
(*pisforce) = true;
}
result = 0; result = 0;
} }
} }
} }
}
if(0 != result){ if(0 != result){
// finally, "path" object did not find. Add no object cache. // finally, "path" object did not find. Add no object cache.