def METHOD_NAME(
        func: Callable[..., Any],
        path: str,
        exc: tuple[type[OSError], OSError, TracebackType],
) -> None:
    excvalue = exc[1]
    if (
            func in (os.rmdir, os.remove, os.unlink) and
            excvalue.errno in {errno.EACCES, errno.EPERM}
    ):
        for p in (path, os.path.dirname(path)):
            os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
        func(path)
    else:
        raise