(path, dir_fd, onexc)
| 712 | |
| 713 | # Version using fd-based APIs to protect against races |
| 714 | def _rmtree_safe_fd(path, dir_fd, onexc): |
| 715 | # While the unsafe rmtree works fine on bytes, the fd based does not. |
| 716 | if isinstance(path, bytes): |
| 717 | path = os.fsdecode(path) |
| 718 | stack = [(os.lstat, dir_fd, path, None)] |
| 719 | try: |
| 720 | while stack: |
| 721 | _rmtree_safe_fd_step(stack, onexc) |
| 722 | finally: |
| 723 | # Close any file descriptors still on the stack. |
| 724 | while stack: |
| 725 | func, fd, path, entry = stack.pop() |
| 726 | if func is not os.close: |
| 727 | continue |
| 728 | try: |
| 729 | os.close(fd) |
| 730 | except OSError as err: |
| 731 | onexc(os.close, path, err) |
| 732 | |
| 733 | def _rmtree_safe_fd_step(stack, onexc): |
| 734 | # Each stack item has four elements: |
nothing calls this directly
no test coverage detected
searching dependent graphs…