Better handling of fs.rmtree errors on Windows // Issue #2916

This commit is contained in:
Ivan Kravets
2019-08-19 12:48:57 +03:00
parent 1dc15326c9
commit bf59dda01b

View File

@ -148,13 +148,15 @@ def match_src_files(src_dir, src_filter=None, src_exts=None):
def rmtree(path):
def _onerror(_, name, __):
def _onerror(func, path, __):
try:
os.chmod(name, stat.S_IWRITE)
os.remove(name)
st_mode = os.stat(path).st_mode
if st_mode & stat.S_IREAD:
os.chmod(path, st_mode | stat.S_IWRITE)
func(path)
except Exception as e: # pylint: disable=broad-except
click.secho("%s \nPlease manually remove the file `%s`" %
(str(e), name),
(str(e), path),
fg="red",
err=True)