Fix "PermissionError: [WinError 32] The process cannot access the file" on Windows

This commit is contained in:
Ivan Kravets
2020-08-01 15:36:28 +03:00
parent a1970bbfe3
commit 41c2d64ef0
3 changed files with 9 additions and 3 deletions

View File

@ -61,7 +61,7 @@ class PackageManagerDownloadMixin(object):
return dl_path
with_progress = not silent and not app.is_disabled_progressbar()
tmp_path = tempfile.mkstemp(dir=self.get_download_dir())[1]
tmp_fd, tmp_path = tempfile.mkstemp(dir=self.get_download_dir())
try:
with LockFile(dl_path):
try:
@ -86,9 +86,11 @@ class PackageManagerDownloadMixin(object):
raise e
if checksum:
fd.verify(checksum)
shutil.copyfile(tmp_path, dl_path)
os.close(tmp_fd)
os.rename(tmp_path, dl_path)
finally:
if os.path.isfile(tmp_path):
os.close(tmp_fd)
os.remove(tmp_path)
assert os.path.isfile(dl_path)

View File

@ -64,6 +64,10 @@ class RegistryFileMirrorsIterator(object):
response.headers.get("X-PIO-Content-SHA256"),
)
def next(self):
""" For Python 2 compatibility """
return self.__next__()
def get_http_client(self):
if self._base_url not in RegistryFileMirrorsIterator.HTTP_CLIENT_INSTANCES:
RegistryFileMirrorsIterator.HTTP_CLIENT_INSTANCES[

View File

@ -71,7 +71,7 @@ def test_find_pkg_root(isolated_pio_core, tmpdir_factory):
# library manager should create "library.json"
lm = LibraryPackageManager()
spec = PackageSpec("custom-name@1.0.0")
pkg_root = lm.find_pkg_root(pkg_dir, spec)
pkg_root = lm.find_pkg_root(str(pkg_dir), spec)
manifest_path = os.path.join(pkg_root, "library.json")
assert os.path.realpath(str(root_dir)) == os.path.realpath(pkg_root)
assert os.path.isfile(manifest_path)