Skip to content

Commit 97442dc

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

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
@@ -313,6 +313,12 @@ Directory and files operations
313313
handled by calling a handler specified by *onexc* or *onerror* or, if both
314314
are omitted, exceptions are propagated to the caller.
315315

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

0 commit comments

Comments
 (0)