diff --git a/HISTORY.rst b/HISTORY.rst index 2b307a33d7..22461dad10 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -41,6 +41,7 @@ PlatformIO Core 6 * Fixed an issue when the `build_unflags `__ option was not applied to the ``ASPPFLAGS`` scope * Fixed an issue on Windows OS when flags were wrapped to the temporary file while generating the `Compilation database "compile_commands.json" `__ * Fixed an issue with the `LDF `__ when recursively scanning dependencies in the ``chain`` mode +* Fixed a "PermissionError" on Windows when running "clean" or "cleanall" targets (`issue #4331 `_) 6.0.2 (2022-06-01) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/builder/tools/piotarget.py b/platformio/builder/tools/piotarget.py index 7436acaf64..2dfdf3d8da 100644 --- a/platformio/builder/tools/piotarget.py +++ b/platformio/builder/tools/piotarget.py @@ -43,26 +43,19 @@ def _relpath(path): def _clean_dir(path): clean_rel_path = _relpath(path) - for root, _, files in os.walk(path): - for f in files: - dst = os.path.join(root, f) - os.remove(dst) - print( - "Removed %s" - % (dst if not clean_rel_path.startswith(".") else _relpath(dst)) - ) + print(f"Removing `{clean_rel_path}` folder...", end="") + fs.rmtree(path) + print(" done!") build_dir = env.subst("$BUILD_DIR") libdeps_dir = env.subst("$PROJECT_LIBDEPS_DIR") if os.path.isdir(build_dir): _clean_dir(build_dir) - fs.rmtree(build_dir) else: print("Build environment is clean") if clean_all and os.path.isdir(libdeps_dir): _clean_dir(libdeps_dir) - fs.rmtree(libdeps_dir) print("Done cleaning")