@@ -1636,7 +1636,7 @@ Copying, renaming and deleting
1636
1636
.. method :: Path.unlink(missing_ok=False)
1637
1637
1638
1638
Remove this file or symbolic link. If the path points to a directory,
1639
- use :func: `Path.rmdir ` instead.
1639
+ use :func: `Path.rmdir ` or :func: ` Path.delete ` instead.
1640
1640
1641
1641
If *missing_ok * is false (the default), :exc: `FileNotFoundError ` is
1642
1642
raised if the path does not exist.
@@ -1650,33 +1650,40 @@ Copying, renaming and deleting
1650
1650
1651
1651
.. method :: Path.rmdir()
1652
1652
1653
- Remove this directory. The directory must be empty.
1653
+ Remove this directory. The directory must be empty; use
1654
+ :meth: `Path.delete ` to remove a non-empty directory.
1654
1655
1655
1656
1656
- .. method :: Path.rmtree (ignore_errors=False, on_error=None)
1657
+ .. method :: Path.delete (ignore_errors=False, on_error=None)
1657
1658
1658
- Recursively delete this entire directory tree. The path must not refer to a symlink.
1659
+ Delete this file or directory. If this path refers to a non-empty
1660
+ directory, its files and sub-directories are deleted recursively.
1659
1661
1660
- If *ignore_errors * is true, errors resulting from failed removals will be
1661
- ignored. If *ignore_errors * is false or omitted, and a function is given to
1662
- *on_error *, it will be called each time an exception is raised. If neither
1663
- *ignore_errors * nor *on_error * are supplied, exceptions are propagated to
1664
- the caller.
1662
+ If *ignore_errors * is true, errors resulting from failed deletions will be
1663
+ ignored. If *ignore_errors * is false or omitted, and a callable is given as
1664
+ the optional *on_error * argument, it will be called with one argument of
1665
+ type :exc: `OSError ` each time an exception is raised. The callable can
1666
+ handle the error to continue the deletion process or re-raise it to stop.
1667
+ Note that the filename is available as the :attr: `~OSError.filename `
1668
+ attribute of the exception object. If neither *ignore_errors * nor
1669
+ *on_error * are supplied, exceptions are propagated to the caller.
1665
1670
1666
1671
.. note ::
1667
1672
1668
- On platforms that support the necessary fd-based functions, a symlink
1669
- attack-resistant version of :meth: `~Path.rmtree ` is used by default. On
1670
- other platforms, the :func: `~Path.rmtree ` implementation is susceptible
1671
- to a symlink attack: given proper timing and circumstances, attackers
1672
- can manipulate symlinks on the filesystem to delete files they would not
1673
- be able to access otherwise.
1674
-
1675
- If the optional argument *on_error * is specified, it should be a callable;
1676
- it will be called with one argument of type :exc: `OSError `. The
1677
- callable can handle the error to continue the deletion process or re-raise
1678
- it to stop. Note that the filename is available as the :attr: `~OSError.filename `
1679
- attribute of the exception object.
1673
+ When deleting non-empty directories on platforms that lack the necessary
1674
+ file descriptor-based functions, the :meth: `~Path.delete ` implementation
1675
+ is susceptible to a symlink attack: given proper timing and
1676
+ circumstances, attackers can manipulate symlinks on the filesystem to
1677
+ delete files they would not be able to access otherwise. Applications
1678
+ can use the :data: `~Path.delete.avoids_symlink_attacks ` method attribute
1679
+ to determine whether the implementation is immune to this attack.
1680
+
1681
+ .. attribute :: delete.avoids_symlink_attacks
1682
+
1683
+ Indicates whether the current platform and implementation provides a
1684
+ symlink attack resistant version of :meth: `~Path.delete `. Currently
1685
+ this is only true for platforms supporting fd-based directory access
1686
+ functions.
1680
1687
1681
1688
.. versionadded :: 3.14
1682
1689
0 commit comments