Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
17f02bb
GH-89727: Fix `shutil.rmtree()` recursion error on deep trees.
barneygale Apr 1, 2023
48dc5db
Delay urllib import
barneygale Apr 1, 2023
6e92b27
Fix up filenames in exceptions
barneygale Apr 1, 2023
c042220
Restore `shutil._rmtree_islink()`
barneygale Apr 1, 2023
e268e89
Tidy up exception handling
barneygale Apr 1, 2023
3f40cb0
Better compatibility with shutil tests.
barneygale Apr 1, 2023
b59bda8
Move main implementation into pathlib
barneygale Apr 1, 2023
c174376
Make `_fwalk()` private, tidy up naming.
barneygale Apr 1, 2023
0e8d8e6
Fix tests
barneygale Apr 1, 2023
fea58ab
Fix missing filename in exception, tidy up more naming.
barneygale Apr 1, 2023
bff0f5e
More cleanup
barneygale Apr 1, 2023
3b21684
Even more tidy-up
barneygale Apr 1, 2023
5abee55
Reduce diff a bit
barneygale Apr 2, 2023
57173d9
Performance improvements
barneygale Apr 2, 2023
58070d9
Simplify rmtree (h/t eryksun)
barneygale Apr 2, 2023
d61baa1
More performance tweaks
barneygale Apr 2, 2023
e983dd7
Make `error._func` private, as it's only intended for `shutil.rmtree()`
barneygale Apr 3, 2023
5387d32
Improve tests
barneygale Apr 3, 2023
75541fb
Improve performance
barneygale Apr 3, 2023
698db60
Merge branch 'main' into pathlib-fwalk
barneygale Apr 3, 2023
74cdd6c
Supply relative paths to `rmdir()` in fd-based walk.
barneygale Apr 7, 2023
c17d07c
Handle rmdir() and unlink() not accepting dir_fd
barneygale Apr 7, 2023
b4f120c
Move rmtree() implementation back into shutil.
barneygale Apr 12, 2023
e856ccb
Restore missing dir_fd check
barneygale Apr 12, 2023
d1e349c
Remove unnecessary change to test
barneygale Apr 12, 2023
63e55e1
Reduce memory usage a bit.
barneygale Apr 12, 2023
f7c5352
Reduce diff
barneygale Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests
  • Loading branch information
barneygale committed Apr 1, 2023
commit 0e8d8e613e96ef617ee305bd0c657788190257db
26 changes: 13 additions & 13 deletions Lib/pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ def _walk(top_down, follow_symlinks, follow_junctions, use_fd, actions):
entries = [] if use_fd and not top_down and not follow_symlinks else None
dirnames = []
filenames = []
if use_fd:
name = path if dir_fd is None else path.name
orig_st = None
try:
try:
if use_fd:
name = path if dir_fd is None else path.name
orig_st = None
if not follow_symlinks:
if entry:
orig_st = entry.stat(follow_symlinks=False)
Expand All @@ -244,15 +244,15 @@ def _walk(top_down, follow_symlinks, follow_junctions, use_fd, actions):
raise exc
result = path, dirnames, filenames, fd
scandir_it = os.scandir(fd)
except OSError as exc:
if not hasattr(exc, 'func'):
exc.func = os.scandir
exc.filename = str(path)
raise exc
else:
fd = None
result = path, dirnames, filenames
scandir_it = path._scandir()
else:
fd = None
result = path, dirnames, filenames
scandir_it = path._scandir()
except OSError as exc:
if not hasattr(exc, 'func'):
exc.func = os.scandir
exc.filename = str(path)
raise exc

with scandir_it:
for entry in scandir_it:
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,14 @@ def test_rmtree_uses_safe_fd_version_if_available(self):
d = os.path.join(tmp_dir, 'a')
os.mkdir(d)
try:
real_fwalk = pathlib.Path.fwalk
real_fwalk = pathlib.Path._fwalk
class Called(Exception): pass
def _raiser(*args, **kwargs):
raise Called
pathlib.Path.fwalk = _raiser
pathlib.Path._fwalk = _raiser
self.assertRaises(Called, shutil.rmtree, d)
finally:
pathlib.Path.fwalk = real_fwalk
pathlib.Path._fwalk = real_fwalk
else:
self.assertFalse(shutil.rmtree.avoids_symlink_attacks)

Expand Down