[V3] Set r/w access before deleting files (#1412)

* [V3] set access before deleting

* [V3] move+rename do_delete and use in repo removal in downloader
This commit is contained in:
palmtree5
2018-03-20 14:46:15 -08:00
committed by Will
parent 2e9a0de4a1
commit eb3b6346bb
3 changed files with 30 additions and 20 deletions

View File

@@ -1,4 +1,8 @@
__all__ = ['TYPE_CHECKING', 'NewType']
__all__ = ['TYPE_CHECKING', 'NewType', 'safe_delete']
from pathlib import Path
import os
import shutil
try:
from typing import TYPE_CHECKING
@@ -10,3 +14,12 @@ try:
except ImportError:
def NewType(name, tp):
return type(name, (tp,), {})
def safe_delete(pth: Path):
if pth.exists():
for root, dirs, files in os.walk(str(pth)):
os.chmod(root, 0o755)
for d in dirs:
os.chmod(os.path.join(root, d), 0o755)
shutil.rmtree(str(pth), ignore_errors=True)