@@ -1092,19 +1092,20 @@ void S3FileSystem::Write(FileHandle &handle, void *buffer, int64_t nr_bytes, idx
10921092}
10931093
10941094static bool Match (vector<string>::const_iterator key, vector<string>::const_iterator key_end,
1095- vector<string>::const_iterator pattern, vector<string>::const_iterator pattern_end) {
1095+ vector<string>::const_iterator pattern, vector<string>::const_iterator pattern_end, bool completed ) {
10961096
1097- while (key != key_end && pattern != pattern_end) {
1098- if (*key == " **" ) {
1097+ if (key == key_end && !completed) {
10991098 return true ;
11001099 }
1100+
1101+ while (key != key_end && pattern != pattern_end) {
11011102 if (*pattern == " **" ) {
11021103 if (std::next (pattern) == pattern_end) {
11031104 return true ;
11041105 }
11051106 pattern ++;
11061107 while (key != key_end) {
1107- if (Match (key, key_end, pattern, pattern_end)) {
1108+ if (Match (key, key_end, pattern, pattern_end, completed )) {
11081109 return true ;
11091110 }
11101111 key++;
@@ -1117,7 +1118,7 @@ static bool Match(vector<string>::const_iterator key, vector<string>::const_iter
11171118 key++;
11181119 pattern++;
11191120 }
1120- if (*pattern == " **" ) {
1121+ if (*pattern == " **" && !completed ) {
11211122 while (*pattern == " **" ) pattern++;
11221123 if (pattern == pattern_end) {
11231124 return true ;
@@ -1197,8 +1198,7 @@ bool S3GlobResult::ExpandNextPath() const {
11971198 vector<string> pattern_splits = StringUtil::Split (parsed_s3_url.key , " /" );
11981199 vector<string> key_splits = StringUtil::Split (current_common_prefix, " /" );
11991200 // pattern_splits.resize(key_splits.size());
1200- key_splits.push_back (" **" );
1201- const bool is_match = Match (key_splits.begin (), key_splits.end (), pattern_splits.begin (), pattern_splits.end ());
1201+ const bool is_match = Match (key_splits.begin (), key_splits.end (), pattern_splits.begin (), pattern_splits.end (), false );
12021202 std::cout << current_common_prefix << " \t " << parsed_s3_url.key << " \t " << (is_match ? " MATCH" : " no" )<< " \n " ;
12031203 if (is_match) {
12041204 auto prefix_res = AWSListObjectV2::Request (prefix_path, *http_params, s3_auth_params,
@@ -1250,7 +1250,7 @@ bool S3GlobResult::ExpandNextPath() const {
12501250 for (auto &s3_key : s3_keys) {
12511251
12521252 vector<string> key_splits = StringUtil::Split (s3_key.path , " /" );
1253- bool is_match = Match (key_splits.begin (), key_splits.end (), pattern_splits.begin (), pattern_splits.end ());
1253+ bool is_match = Match (key_splits.begin (), key_splits.end (), pattern_splits.begin (), pattern_splits.end (), true );
12541254
12551255 if (is_match) {
12561256 auto result_full_url = parsed_s3_url.prefix + parsed_s3_url.bucket + " /" + s3_key.path ;
0 commit comments