Skip to content
Commits on Source (3)
......@@ -29,7 +29,7 @@ from diffoscope.difference import Difference
from .utils.file import File
from .utils.archive import Archive
from .utils.compare import compare_files
from .zip import Zipinfo, ZipinfoVerbose
from .zip import zipinfo_differences
from .missing_file import MissingFile
logger = logging.getLogger(__name__)
......@@ -67,12 +67,13 @@ class ApkContainer(Archive):
stdout=subprocess.PIPE,
)
# Optionally extract the classes.dex file; apktool does not do this.
subprocess.call(
('unzip', '-d', self._unpacked, self.source.path, 'classes.dex'),
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
# Optionally extract a few files that apktool does not
for x in ('classes.dex', 'resources.arsc'):
subprocess.call(
('unzip', '-d', self._unpacked, self.source.path, x),
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
for root, _, files in os.walk(self._unpacked):
current_dir = []
......@@ -175,10 +176,7 @@ class ApkFile(File):
CONTAINER_CLASS = ApkContainer
def compare_details(self, other, source=None):
zipinfo_difference = Difference.from_command(
Zipinfo, self.path, other.path
) or Difference.from_command(ZipinfoVerbose, self.path, other.path)
return [zipinfo_difference]
return zipinfo_differences(self, other)
def filter_apk_metadata(filepath, archive_name):
......
......@@ -125,6 +125,20 @@ class BsdtarVerbose(Command):
return ['bsdtar', '-tvf', self.path]
def zipinfo_differences(file, other):
"""
Run all our zipinfo variants.
"""
for x in (Zipinfo, ZipinfoVerbose, BsdtarVerbose):
result = Difference.from_command(x, file.path, other.path)
# We only return the 'best' one
if result is not None:
return [result]
return []
class ZipDirectory(Directory, ArchiveMember):
def __init__(self, archive, member_name):
ArchiveMember.__init__(self, archive, member_name)
......@@ -192,20 +206,11 @@ class ZipFile(File):
def compare_details(self, other, source=None):
differences = []
zipinfo_difference = None
if Config().exclude_directory_metadata != 'recursive':
for x in (Zipinfo, ZipinfoVerbose, BsdtarVerbose):
zipinfo_difference = Difference.from_command(
x, self.path, other.path
)
if zipinfo_difference:
break
zipnote_difference = Difference.from_command(
Zipnote, self.path, other.path
differences.extend(zipinfo_differences(self, other))
differences.append(
Difference.from_command(Zipnote, self.path, other.path)
)
for x in (zipinfo_difference, zipnote_difference):
if x is not None:
differences.append(x)
return differences
......