[Utils] Modify chmod use in safe_delete (#2701)

- Takes a pessmisitc approach that it's possible chmod succeeds, but
 deletion fails and does not make the entire dir world writeable
This commit is contained in:
Michael H 2019-06-29 10:45:44 -04:00 committed by Toby Harradine
parent 8bf86f33a3
commit 8a72840de0

View File

@ -62,13 +62,13 @@ logging.getLogger().addFilter(_fuzzy_log_filter)
def safe_delete(pth: Path):
if pth.exists():
for root, dirs, files in os.walk(str(pth)):
os.chmod(root, 0o755)
os.chmod(root, 0o700)
for d in dirs:
os.chmod(os.path.join(root, d), 0o755)
os.chmod(os.path.join(root, d), 0o700)
for f in files:
os.chmod(os.path.join(root, f), 0o755)
os.chmod(os.path.join(root, f), 0o700)
shutil.rmtree(str(pth), ignore_errors=True)