@@ -97,12 +97,12 @@ def __init__(
9797 max_depth (int, optional): Maximum directory depth to walk.
9898 filter_glob (list, optional): If supplied, this parameter
9999 should be a list of path patterns e.g. ``["foo/**/*.py"]``.
100- Resources will only be returned if their global patah
101- matches one of the patterns.
100+ Resources will only be returned if their global path or
101+ an extension of it matches one of the patterns.
102102 exclude_glob (list, optional): If supplied, this parameter
103103 should be a list of path patterns e.g. ``["foo/**/*.py"]``.
104- Resources will only be returned if their global patah
105- matches one of the patterns.
104+ Resources will not be returned if their global path or
105+ an extension of it matches one of the patterns.
106106
107107 """
108108 if search not in ("breadth" , "depth" ):
@@ -215,13 +215,18 @@ def _iter_walk(
215215 def _check_open_dir (self , fs , path , info ):
216216 # type: (FS, Text, Info) -> bool
217217 """Check if a directory should be considered in the walk."""
218+ full_path = ("" if path == "/" else path ) + "/" + info .name
218219 if self .exclude_dirs is not None and fs .match (self .exclude_dirs , info .name ):
219220 return False
220- if self .exclude_glob is not None and fs .match (self .exclude_glob , path ):
221+ if self .exclude_glob is not None and fs .match (self .exclude_glob , full_path ):
221222 return False
222- if self .filter_dirs is not None and not fs .match (self .filter_dirs , info .name ):
223+ if self .filter_dirs is not None and not fs .match (
224+ self .filter_dirs , info .name , accept_prefix = True
225+ ):
223226 return False
224- if self .filter_glob is not None and not fs .match (self .filter_glob , path ):
227+ if self .filter_glob is not None and not fs .match (
228+ self .filter_glob , full_path , accept_prefix = True
229+ ):
225230 return False
226231 return self .check_open_dir (fs , path , info )
227232
@@ -268,15 +273,23 @@ def check_scan_dir(self, fs, path, info):
268273 """
269274 return True
270275
271- def _check_file (self , fs , info ):
272- # type: (FS, Info) -> bool
276+ def _check_file (self , fs , dir_path , info ):
277+ # type: (FS, Text, Info) -> bool
273278 """Check if a filename should be included."""
274279 # Weird check required for backwards compatibility, when _check_file did not exist.
275280 if Walker ._check_file == type (self )._check_file :
276281 if self .exclude is not None and fs .match (self .exclude , info .name ):
277282 return False
283+ if self .exclude_glob is not None and fs .match (
284+ self .exclude_glob , dir_path + "/" + info .name
285+ ):
286+ return False
278287 if self .filter is not None and not fs .match (self .filter , info .name ):
279288 return False
289+ if self .filter_glob is not None and not fs .match (
290+ self .filter_glob , dir_path + "/" + info .name , accept_prefix = True
291+ ):
292+ return False
280293 return self .check_file (fs , info )
281294
282295 def check_file (self , fs , info ):
@@ -462,7 +475,7 @@ def _walk_breadth(
462475 if _check_scan_dir (fs , dir_path , info , _depth ):
463476 push (_combine (dir_path , info .name ))
464477 else :
465- if _check_file (fs , info ):
478+ if _check_file (fs , dir_path , info ):
466479 yield dir_path , info # Found a file
467480 yield dir_path , None # End of directory
468481
@@ -513,7 +526,7 @@ def _walk_depth(
513526 else :
514527 yield dir_path , info
515528 else :
516- if _check_file (fs , info ):
529+ if _check_file (fs , dir_path , info ):
517530 yield dir_path , info
518531
519532
0 commit comments