MCPcopy Index your code
hub / github.com/python/cpython / _rmtree_safe_fd

Function _rmtree_safe_fd

Lib/shutil.py:714–731  ·  view source on GitHub ↗
(path, dir_fd, onexc)

Source from the content-addressed store, hash-verified

712
713# Version using fd-based APIs to protect against races
714def _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
733def _rmtree_safe_fd_step(stack, onexc):
734 # Each stack item has four elements:

Callers

nothing calls this directly

Calls 4

_rmtree_safe_fd_stepFunction · 0.85
onexcFunction · 0.85
popMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…