Commit 28695191 authored by Chris Lamb's avatar Chris Lamb 💬

Compare .zip file comments with zipnote. (Closes: #901757)

parent ffc61b45
Pipeline #27682 failed with stage
in 12 minutes and 51 seconds
......@@ -7,7 +7,7 @@
# $ mv debian/tests/control.tmp debian/tests/control
Tests: pytest-with-recommends
Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, apktool [!ppc64el !s390x], binutils-multiarch, bzip2, caca-utils, colord, db-util, default-jdk-headless | default-jdk | java-sdk, device-tree-compiler, docx2txt, e2fsprogs, enjarify, fontforge-extras, fp-utils [!ppc64el !s390x], genisoimage, gettext, ghc, ghostscript, giflib-tools, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, ocaml-nox, odt2txt, openssh-client, pgpdump, poppler-utils, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, zip, python3-argcomplete, python3-binwalk, python3-defusedxml, python3-distro, python3-guestfs, python3-jsondiff, python3-progressbar, python3-pypdf2, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Tests: pytest
Depends: diffoscope, python3-pytest, file
......
......@@ -57,6 +57,43 @@ class ZipinfoVerbose(Zipinfo):
return ['zipinfo', '-v', self.path]
class Zipnote(Command):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.flag = False
@tool_required('zipnote')
def cmdline(self):
return ['zipnote', self.path]
def filter(self, line):
"""
Example output from zipnote(1):
@ foo
hello
@ (comment above this line)
@ (zip file comment below this line)
goodbye
"""
if line == b'@ (zip file comment below this line)\n':
self.flag = True
return b'Zip file comment: '
if line == b'@ (comment above this line)\n':
self.flag = False
return b'\n\n' # spacer
if line.startswith(b'@ '):
filename = line[2:-1].decode()
self.flag = True
return "Filename: {}\nComment: ".format(filename).encode()
return line[:-1] if self.flag else b''
class BsdtarVerbose(Command):
@tool_required('bsdtar')
def cmdline(self):
......@@ -125,10 +162,15 @@ class ZipFile(File):
r'^(Zip archive|Java archive|EPUB document|OpenDocument (Text|Spreadsheet|Presentation|Drawing|Formula|Template|Text Template))\b')
def compare_details(self, other, source=None):
differences = []
zipinfo_difference = Difference.from_command(Zipinfo, self.path, other.path) or \
Difference.from_command(ZipinfoVerbose, self.path, other.path) or \
Difference.from_command(BsdtarVerbose, self.path, other.path)
return [zipinfo_difference]
zipnote_difference = 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
class MozillaZipCommandMixin(object):
......
......@@ -267,6 +267,9 @@ EXTERNAL_TOOLS = {
'arch': 'unzip',
'FreeBSD': 'unzip',
},
'zipnote': {
'debian': 'zip',
},
'procyon': {
'debian': 'procyon-decompiler',
},
......
......@@ -33,6 +33,8 @@ encrypted_zip1 = load_fixture('encrypted1.zip')
encrypted_zip2 = load_fixture('encrypted2.zip')
mozzip1 = load_fixture('test1.mozzip')
mozzip2 = load_fixture('test2.mozzip')
test_comment1 = load_fixture('test_comment1.zip')
test_comment2 = load_fixture('test_comment2.zip')
def test_identification(zip1):
......@@ -117,3 +119,14 @@ def test_mozzip_compare_non_existing(monkeypatch, mozzip1):
def test_encrypted(encrypted_zip1, encrypted_zip2):
difference = encrypted_zip1.compare(encrypted_zip2)
assert difference is not None
@pytest.fixture
def comment_differences(test_comment1, test_comment2):
return test_comment1.compare(test_comment2).details
@skip_unless_tools_exist('zipnote')
def test_commented(comment_differences):
expected_diff = get_data('comment_zipinfo_expected_diff')
assert comment_differences[1].unified_diff == expected_diff
@@ -1,4 +1,4 @@
Filename: foo
-Comment:
+Comment: hello
-Zip file comment:
+Zip file comment: goodbye
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment