Skip to content

Commit

Permalink
Improve deletion of junctions
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Aug 19, 2024
1 parent 2420b85 commit b934731
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,9 @@ def delete(self):
"""
Delete this file or directory (including all sub-directories).
"""
if self.is_dir(follow_symlinks=False):
if self.is_symlink() or self.is_junction():
self.unlink()
elif self.is_dir():
def on_error(err):
raise err
results = self.walk(
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_pathlib/test_pathlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,10 @@ def test_delete_outer_junction(self):
spam = src / 'spam'
spam.write_text('')
_winapi.CreateJunction(str(src), str(dst))
self.assertRaises(OSError, dst.delete)
dst.delete()
self.assertFalse(dst.exists())
self.assertTrue(spam.exists())
self.assertTrue(src.exists())

@unittest.skipUnless(delete_use_fd_functions, "requires safe delete")
def test_delete_fails_on_close(self):
Expand Down

0 comments on commit b934731

Please sign in to comment.