Skip to content

Commit

Permalink
Improve checking of package structure after unpacking // Issue #1462
Browse files Browse the repository at this point in the history
  • Loading branch information
ivankravets committed Jul 14, 2018
1 parent 72d260c commit a14f2d2
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions platformio/unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def __init__(self, arhfileobj):
def get_items(self):
raise NotImplementedError()

def get_item_filename(self, item):
raise NotImplementedError()

def extract_item(self, item, dest_dir):
self._afo.extract(item, dest_dir)
self.after_extract(item, dest_dir)
Expand All @@ -50,10 +53,8 @@ def __init__(self, archpath):
def get_items(self):
return self._afo.getmembers()

def after_extract(self, item, dest_dir):
item_path = join(dest_dir, item.name)
if not islink(item_path) and not exists(item_path):
raise exception.ExtractArchiveItemError(item.name, dest_dir)
def get_item_filename(self, item):
return item.name


class ZIPArchive(ArchiveBase):
Expand All @@ -76,10 +77,10 @@ def preserve_mtime(item, dest_dir):
def get_items(self):
return self._afo.infolist()

def get_item_filename(self, item):
return item.filename

def after_extract(self, item, dest_dir):
item_path = join(dest_dir, item.filename)
if not islink(item_path) and not exists(item_path):
raise exception.ExtractArchiveItemError(item.filename, dest_dir)
self.preserve_permissions(item, dest_dir)
self.preserve_mtime(item, dest_dir)

Expand Down Expand Up @@ -114,4 +115,12 @@ def unpack(self, dest_dir=".", with_progress=True):
with click.progressbar(items, label="Unpacking") as pb:
for item in pb:
self._unpacker.extract_item(item, dest_dir)

# check on disk
for item in self._unpacker.get_items():
filename = self._unpacker.get_item_filename(item)
item_path = join(dest_dir, filename)
if not islink(item_path) and not exists(item_path):
raise exception.ExtractArchiveItemError(filename, dest_dir)

return True

0 comments on commit a14f2d2

Please sign in to comment.