From 44a926b30a1b17b31793b05844aa64c8223708db Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Fri, 13 Jul 2018 01:54:37 +0300 Subject: [PATCH] Check package structure after unpacking and raise error when antivirus tool blocks PlatformIO package manager // Resolve #1462 --- HISTORY.rst | 4 ++++ docs | 2 +- platformio/exception.py | 7 +++++++ platformio/unpacker.py | 13 +++++++++---- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 7bc19c63..e567092f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,10 @@ PlatformIO 3.0 - Check maximum allowed "program" and "data" sizes before uploading/programming (`issue #1412 `_) +* Check package structure after unpacking and raise error when antivirus tool + blocks PlatformIO package manager + (`issue #1462 `_) + 3.5.4 (2018-07-03) ~~~~~~~~~~~~~~~~~~ diff --git a/docs b/docs index 14ee4036..e3330b7e 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 14ee40368f8c3683985e04c6cb685befaf9b206d +Subproject commit e3330b7e33e48c11547299183fd0a599c77b01b6 diff --git a/platformio/exception.py b/platformio/exception.py index 01c1be7f..c7d3cd2f 100644 --- a/platformio/exception.py +++ b/platformio/exception.py @@ -102,6 +102,13 @@ class PackageInstallError(PlatformioException): "Please try this solution -> http://bit.ly/faq-package-manager") +class ExtractArchiveItemError(PlatformioException): + + MESSAGE = ( + "Could not extract `{0}` to `{1}`. Try to disable antivirus " + "tool or check this solution -> http://bit.ly/faq-package-manager") + + class FDUnrecognizedStatusCode(PlatformioException): MESSAGE = "Got an unrecognized status code '{0}' when downloaded {1}" diff --git a/platformio/unpacker.py b/platformio/unpacker.py index 38165c40..9c432e21 100644 --- a/platformio/unpacker.py +++ b/platformio/unpacker.py @@ -13,15 +13,14 @@ # limitations under the License. from os import chmod -from os.path import join +from os.path import exists, join from tarfile import open as tarfile_open from time import mktime from zipfile import ZipFile import click -from platformio import util -from platformio.exception import UnsupportedArchiveType +from platformio import exception, util class ArchiveBase(object): @@ -51,6 +50,10 @@ class TARArchive(ArchiveBase): def get_items(self): return self._afo.getmembers() + def after_extract(self, item, dest_dir): + if not exists(join(dest_dir, item.name)): + raise exception.ExtractArchiveItemError(item.name, dest_dir) + class ZIPArchive(ArchiveBase): @@ -73,6 +76,8 @@ class ZIPArchive(ArchiveBase): return self._afo.infolist() def after_extract(self, item, dest_dir): + if not exists(join(dest_dir, item.filename)): + raise exception.ExtractArchiveItemError(item.filename, dest_dir) self.preserve_permissions(item, dest_dir) self.preserve_mtime(item, dest_dir) @@ -89,7 +94,7 @@ class FileUnpacker(object): elif self.archpath.lower().endswith(".zip"): self._unpacker = ZIPArchive(self.archpath) if not self._unpacker: - raise UnsupportedArchiveType(self.archpath) + raise exception.UnsupportedArchiveType(self.archpath) return self def __exit__(self, *args):