From bf59dda01bbabf6efe248773bfc347bd2bd6ea09 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 19 Aug 2019 12:48:57 +0300 Subject: [PATCH] Better handling of fs.rmtree errors on Windows // Issue #2916 --- platformio/fs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/platformio/fs.py b/platformio/fs.py index 7cca5844..a5f61ce5 100644 --- a/platformio/fs.py +++ b/platformio/fs.py @@ -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)