fix xpath selector in bucket listing

the original implementation in get_base_exp() depends on the order of xml return from the server.
patriotically, when listing a directory with sub directory(s), the xml document response contains more than 2 <Prefix> nodes(some of them are in <CommonPrefixes> node).
the source code arbitrarily select the first one in the documents (nodes->nodeTab[0]->xmlChildrenNode).
some s3 compatible service return the list-bucket result in different result, leading the s3fs to a wrong behavior
This commit is contained in:
陈方舟 2018-04-23 15:11:29 +08:00 committed by GitHub
parent 1a23b880d5
commit 04493de767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2724,7 +2724,7 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp)
{ {
xmlXPathObjectPtr marker_xp; xmlXPathObjectPtr marker_xp;
string xmlnsurl; string xmlnsurl;
string exp_string = "//"; string exp_string;
if(!doc){ if(!doc){
return NULL; return NULL;
@ -2733,8 +2733,11 @@ static xmlChar* get_base_exp(xmlDocPtr doc, const char* exp)
if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){ if(!noxmlns && GetXmlNsUrl(doc, xmlnsurl)){
xmlXPathRegisterNs(ctx, (xmlChar*)"s3", (xmlChar*)xmlnsurl.c_str()); xmlXPathRegisterNs(ctx, (xmlChar*)"s3", (xmlChar*)xmlnsurl.c_str());
exp_string += "s3:"; exp_string = "/s3:ListBucketResult/s3:";
} else {
exp_string = "/ListBucketResult/";
} }
exp_string += exp; exp_string += exp;
if(NULL == (marker_xp = xmlXPathEvalExpression((xmlChar *)exp_string.c_str(), ctx))){ if(NULL == (marker_xp = xmlXPathEvalExpression((xmlChar *)exp_string.c_str(), ctx))){