shutil.rmtree handler invoked on error when deleting a directory tree. This retries deleting once before giving up.
(function, path, excinfo)
| 535 | |
| 536 | |
| 537 | def _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 | |
| 564 | def delete(location, _err_handler=_rm_handler): |
nothing calls this directly
no test coverage detected