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.
strpath = path; pisforce = (NULL != pisforce ? pisforce : &forcedir);
(*pisforce) = false;
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,57 +442,50 @@ 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]){
strpath += "/"; // now path is "object", do check "object/" for over checking
result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); strpath += "/";
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$";
result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader)); result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader));
s3fscurl.DestroyCurlHandle(); s3fscurl.DestroyCurlHandle();
} }
} if(0 != result){
if(0 != result){ // now path is "object/", do check "object_$folder$" for over checking
// not found "object/" and "object_$folder$", check no dir object. strpath = strpath.substr(0, strpath.length() - 1);
strpath = path; strpath += "_$folder$";
if(string::npos == strpath.find("_$folder$", 0)){ result = s3fscurl.HeadRequest(strpath.c_str(), (*pheader));
if('/' == strpath[strpath.length() - 1]){ s3fscurl.DestroyCurlHandle();
strpath = strpath.substr(0, strpath.length() - 1);
} if(0 != result){
if(-ENOTEMPTY == directory_empty(strpath.c_str())){ // cut "_$folder$" for over checking "no dir object" after here
// found "no dir object". if(string::npos != (Pos = strpath.find("_$folder$", 0))){
strpath += "/"; strpath = strpath.substr(0, Pos);
forcedir = true;
if(pisforce){
(*pisforce) = true;
} }
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{ }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){ result = 0;
(*pisforce) = true;
}
result = 0;
}
} }
} }
} }