From 687c339f20f4499caac7bf1f920cf78077914b2f Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 12 Sep 2020 23:20:46 +0300 Subject: [PATCH] Fixed a "PermissionError: [WinError 5]" on Windows when external repository is used with `lib_deps` option // Resolve #3664 --- HISTORY.rst | 3 ++- platformio/package/manager/_install.py | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 9c1116ec5c..4503cacbec 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,7 +11,8 @@ PlatformIO Core 5 5.0.2 (2020-09-??) ~~~~~~~~~~~~~~~~~~ -- Fixed an issue with "KeyError: 'versions'" when dependency does not exist in the registry (`issue #3666 `_) +- Fixed a "PermissionError: [WinError 5]" on Windows when external repository is used with `lib_deps `__ option (`issue #3664 `_) +- Fixed a "KeyError: 'versions'" when dependency does not exist in the registry (`issue #3666 `_) 5.0.1 (2020-09-10) ~~~~~~~~~~~~~~~~~~ diff --git a/platformio/package/manager/_install.py b/platformio/package/manager/_install.py index 9d82d6fefd..6cdccf0948 100644 --- a/platformio/package/manager/_install.py +++ b/platformio/package/manager/_install.py @@ -152,7 +152,10 @@ def install_from_url(self, url, spec, checksum=None, silent=False): return self._install_tmp_pkg(pkg_item) finally: if os.path.isdir(tmp_dir): - fs.rmtree(tmp_dir) + try: + shutil.rmtree(tmp_dir) + except: # pylint: disable=bare-except + pass def _install_tmp_pkg(self, tmp_pkg): assert isinstance(tmp_pkg, PackageItem) @@ -213,10 +216,10 @@ def _cleanup_dir(path): # move existing into the new place pkg_dir = os.path.join(self.package_dir, target_dirname) _cleanup_dir(pkg_dir) - shutil.move(dst_pkg.path, pkg_dir) + shutil.copytree(dst_pkg.path, pkg_dir, symlinks=True) # move new source to the destination location _cleanup_dir(dst_pkg.path) - shutil.move(tmp_pkg.path, dst_pkg.path) + shutil.copytree(tmp_pkg.path, dst_pkg.path, symlinks=True) return PackageItem(dst_pkg.path) if action == "detach-new": @@ -233,10 +236,10 @@ def _cleanup_dir(path): ) pkg_dir = os.path.join(self.package_dir, target_dirname) _cleanup_dir(pkg_dir) - shutil.move(tmp_pkg.path, pkg_dir) + shutil.copytree(tmp_pkg.path, pkg_dir, symlinks=True) return PackageItem(pkg_dir) # otherwise, overwrite existing _cleanup_dir(dst_pkg.path) - shutil.move(tmp_pkg.path, dst_pkg.path) + shutil.copytree(tmp_pkg.path, dst_pkg.path, symlinks=True) return PackageItem(dst_pkg.path)