diff --git a/S3/FileLists.py b/S3/FileLists.py index 8ce38d4c5..0737ad9c3 100644 --- a/S3/FileLists.py +++ b/S3/FileLists.py @@ -17,6 +17,7 @@ import sys import glob import copy +import re __all__ = ["fetch_local_list", "fetch_remote_list", "compare_filelists", "filter_exclude_include"] @@ -398,16 +399,12 @@ def _get_filelist_remote(remote_uri, recursive = True): uri_str = str(uri) ## Wildcards used in remote URI? ## If yes we'll need a bucket listing... - if uri_str.find('*') > -1 or uri_str.find('?') > -1: - first_wildcard = uri_str.find('*') - first_questionmark = uri_str.find('?') - if first_questionmark > -1 and first_questionmark < first_wildcard: - first_wildcard = first_questionmark - prefix = uri_str[:first_wildcard] - rest = uri_str[first_wildcard+1:] + wildcard_split_result = re.split("\*|\?", uri_str, maxsplit=1) + if len(wildcard_split_result) == 2: # wildcards found + prefix, rest = wildcard_split_result ## Only request recursive listing if the 'rest' of the URI, ## i.e. the part after first wildcard, contains '/' - need_recursion = rest.find('/') > -1 + need_recursion = '/' in rest objectlist = _get_filelist_remote(S3Uri(prefix), recursive = need_recursion) for key in objectlist: ## Check whether the 'key' matches the requested wildcards