Skip to content

Commit c393c16

Browse files
[3.14] gh-160322: document shutil.rmtree("link/") symlink following behavior (GH-160372) (#160394)
(cherry picked from commit 2c24bc1) Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
1 parent 3234061 commit c393c16

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎Doc/library/shutil.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ Directory and files operations
316316
handled by calling a handler specified by *onexc* or *onerror* or, if both
317317
are omitted, exceptions are propagated to the caller.
318318

319+
If *path* is a symbolic link to a directory followed by a trailing path
320+
separator, such as ``'link/'``, the operating system resolves the link, so
321+
:func:`!rmtree` deletes the contents of the directory it points to and then
322+
fails to remove *path* itself. :class:`pathlib.Path` strips trailing
323+
separators, so ``rmtree(Path('link/'))`` refuses the link as usual.
324+
319325
This function can support :ref:`paths relative to directory descriptors
320326
<dir_fd>`.
321327

0 commit comments

Comments
 (0)