mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-02-17 08:14:42 +04:00
Fix rmtree for readonly directories
This commit is contained in:
parent
77947f212e
commit
da44d4267e
2 changed files with 16 additions and 2 deletions
|
|
@ -158,13 +158,14 @@ def cmd_output(*cmd, **kwargs):
|
|||
|
||||
def rmtree(path):
|
||||
"""On windows, rmtree fails for readonly dirs."""
|
||||
def handle_remove_readonly(func, path, exc): # pragma: no cover (windows)
|
||||
def handle_remove_readonly(func, path, exc):
|
||||
excvalue = exc[1]
|
||||
if (
|
||||
func in (os.rmdir, os.remove, os.unlink) and
|
||||
excvalue.errno == errno.EACCES
|
||||
):
|
||||
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
|
||||
for p in (path, os.path.dirname(path)):
|
||||
os.chmod(p, os.stat(p).st_mode | stat.S_IWUSR)
|
||||
func(path)
|
||||
else:
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue