MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _rm_handler

Function _rm_handler

src/commoncode/fileutils.py:537–561  ·  view source on GitHub ↗

shutil.rmtree handler invoked on error when deleting a directory tree. This retries deleting once before giving up.

(function, path, excinfo)

Source from the content-addressed store, hash-verified

535
536
537def _rm_handler(function, path, excinfo): # NOQA
538 """
539 shutil.rmtree handler invoked on error when deleting a directory tree.
540 This retries deleting once before giving up.
541 """
542 if TRACE:
543 logger_debug("_rm_handler:", "path:", path, "excinfo:", excinfo)
544 if function in (os.rmdir, os.listdir, os.scandir):
545 try:
546 chmod(path, RW, recurse=True)
547 shutil.rmtree(path, True)
548 except Exception:
549 pass
550
551 if os.path.exists(path):
552 logger.warning("Failed to delete directory %s", path)
553
554 elif function == os.remove:
555 try:
556 delete(path, _err_handler=None)
557 except Exception:
558 pass
559
560 if os.path.exists(path):
561 logger.warning("Failed to delete file %s", path)
562
563
564def delete(location, _err_handler=_rm_handler):

Callers

nothing calls this directly

Calls 5

deleteFunction · 0.85
logger_debugFunction · 0.70
chmodFunction · 0.70
existsMethod · 0.45
warningMethod · 0.45

Tested by

no test coverage detected