| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,30 +164,15 @@ class _RecursiveWildcardSelector(_Selector): | |||
| 164 | 164 | def __init__(self, pat, child_parts, flavour, case_sensitive): | |
| 165 | 165 | _Selector.__init__(self, child_parts, flavour, case_sensitive) | |
| 166 | 166 | ||
| 167 | - def _iterate_directories(self, parent_path, scandir): | ||
| 167 | + def _iterate_directories(self, parent_path): | ||
| 168 | 168 | yield parent_path | |
| 169 | - try: | ||
| 170 | - # We must close the scandir() object before proceeding to | ||
| 171 | - # avoid exhausting file descriptors when globbing deep trees. | ||
| 172 | - with scandir(parent_path) as scandir_it: | ||
| 173 | - entries = list(scandir_it) | ||
| 174 | - except OSError: | ||
| 175 | - pass | ||
| 176 | - else: | ||
| 177 | - for entry in entries: | ||
| 178 | - entry_is_dir = False | ||
| 179 | - try: | ||
| 180 | - entry_is_dir = entry.is_dir(follow_symlinks=False) | ||
| 181 | - except OSError: | ||
| 182 | - pass | ||
| 183 | - if entry_is_dir: | ||
| 184 | - path = parent_path._make_child_relpath(entry.name) | ||
| 185 | - for p in self._iterate_directories(path, scandir): | ||
| 186 | - yield p | ||
| 169 | + for dirpath, dirnames, _ in parent_path.walk(): | ||
| 170 | + for dirname in dirnames: | ||
| 171 | + yield dirpath._make_child_relpath(dirname) | ||
| 187 | 172 | ||
| 188 | 173 | def _select_from(self, parent_path, scandir): | |
| 189 | 174 | successor_select = self.successor._select_from | |
| 190 | - for starting_point in self._iterate_directories(parent_path, scandir): | ||
| 175 | + for starting_point in self._iterate_directories(parent_path): | ||
| 191 | 176 | for p in successor_select(starting_point, scandir): | |
| 192 | 177 | yield p | |
| 193 | 178 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1972,6 +1972,17 @@ def test_glob_long_symlink(self): | |||
| 1972 | 1972 | bad_link.symlink_to("bad" * 200) | |
| 1973 | 1973 | self.assertEqual(sorted(base.glob('**/*')), [bad_link]) | |
| 1974 | 1974 | ||
| 1975 | + def test_glob_above_recursion_limit(self): | ||
| 1976 | + recursion_limit = 40 | ||
| 1977 | + # directory_depth > recursion_limit | ||
| 1978 | + directory_depth = recursion_limit + 10 | ||
| 1979 | + base = pathlib.Path(os_helper.TESTFN, 'deep') | ||
| 1980 | + path = pathlib.Path(base, *(['d'] * directory_depth)) | ||
| 1981 | + path.mkdir(parents=True) | ||
| 1982 | + | ||
| 1983 | + with set_recursion_limit(recursion_limit): | ||
| 1984 | + list(base.glob('**')) | ||
| 1985 | + | ||
| 1975 | 1986 | def _check_resolve(self, p, expected, strict=True): | |
| 1976 | 1987 | q = p.resolve(strict) | |
| 1977 | 1988 | self.assertEqual(q, expected) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix issue where :meth:`pathlib.Path.glob` raised :exc:`RecursionError` when | ||
| 2 | + walking deep directory trees. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments