Check package structure after unpacking and raise error when antivirus tool blocks PlatformIO package manager // Resolve #1462

This commit is contained in:
Ivan Kravets
2018-07-13 01:54:37 +03:00
parent 735cfbf850
commit 44a926b30a
4 changed files with 21 additions and 5 deletions

View File

@ -15,6 +15,10 @@ PlatformIO 3.0
- Check maximum allowed "program" and "data" sizes before uploading/programming - Check maximum allowed "program" and "data" sizes before uploading/programming
(`issue #1412 <https://github.com/platformio/platformio-core/issues/1412>`_) (`issue #1412 <https://github.com/platformio/platformio-core/issues/1412>`_)
* Check package structure after unpacking and raise error when antivirus tool
blocks PlatformIO package manager
(`issue #1462 <https://github.com/platformio/platformio-core/issues/1462>`_)
3.5.4 (2018-07-03) 3.5.4 (2018-07-03)
~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~

2
docs

Submodule docs updated: 14ee40368f...e3330b7e33

View File

@ -102,6 +102,13 @@ class PackageInstallError(PlatformioException):
"Please try this solution -> http://bit.ly/faq-package-manager") "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): class FDUnrecognizedStatusCode(PlatformioException):
MESSAGE = "Got an unrecognized status code '{0}' when downloaded {1}" MESSAGE = "Got an unrecognized status code '{0}' when downloaded {1}"

View File

@ -13,15 +13,14 @@
# limitations under the License. # limitations under the License.
from os import chmod from os import chmod
from os.path import join from os.path import exists, join
from tarfile import open as tarfile_open from tarfile import open as tarfile_open
from time import mktime from time import mktime
from zipfile import ZipFile from zipfile import ZipFile
import click import click
from platformio import util from platformio import exception, util
from platformio.exception import UnsupportedArchiveType
class ArchiveBase(object): class ArchiveBase(object):
@ -51,6 +50,10 @@ class TARArchive(ArchiveBase):
def get_items(self): def get_items(self):
return self._afo.getmembers() 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): class ZIPArchive(ArchiveBase):
@ -73,6 +76,8 @@ class ZIPArchive(ArchiveBase):
return self._afo.infolist() return self._afo.infolist()
def after_extract(self, item, dest_dir): 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_permissions(item, dest_dir)
self.preserve_mtime(item, dest_dir) self.preserve_mtime(item, dest_dir)
@ -89,7 +94,7 @@ class FileUnpacker(object):
elif self.archpath.lower().endswith(".zip"): elif self.archpath.lower().endswith(".zip"):
self._unpacker = ZIPArchive(self.archpath) self._unpacker = ZIPArchive(self.archpath)
if not self._unpacker: if not self._unpacker:
raise UnsupportedArchiveType(self.archpath) raise exception.UnsupportedArchiveType(self.archpath)
return self return self
def __exit__(self, *args): def __exit__(self, *args):