INNER CODE UNIT · Python

_handle_remove_readonly

ArcSurge/Termius-Pro-zh_CN · lang.py:60

def _handle_remove_readonly(func, path, _):
    """shutil.rmtree 的错误处理回调:移除只读属性后重试"""
    os.chmod(path, stat.S_IWRITE)
    func(path)


def safe_rmtree(path):
    """安全删除目录,处理只读文件

    Python 3.12+ 使用 onexc,之前版本使用 onerror
    """
    if not os.path.exists(path):
        return
    if sys.version_info >= (3, 12):
        shutil.rmtree(path, onexc=_handle_remove_readonly)
    else:
        shutil.rmtree(path, onerror=_handle_remove_readonly)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…