[Git][reproducible-builds/diffoscope][master] 3 commits: Handle FAT filesystem with fsimage comparator
Mattia Rizzolo
gitlab at salsa.debian.org
Fri Oct 12 18:19:25 CEST 2018
Mattia Rizzolo pushed to branch master at Reproducible Builds / diffoscope
Commits:
da3b97a1 by Marek Marczykowski-Górecki at 2018-10-09T13:28:17Z
Handle FAT filesystem with fsimage comparator
Signed-off-by: Marek Marczykowski-Górecki <marmarek at invisiblethingslab.com>
- - - - -
575f99bc by Marek Marczykowski-Górecki at 2018-10-12T15:30:41Z
Add test for FAT fsimage comparator
Only test[12].fat12 are actual FAT images, test1.fat{16,32} are
truncated to 200 bytes, just enough to pass identification test.
Signed-off-by: Marek Marczykowski-Górecki <marmarek at invisiblethingslab.com>
- - - - -
fa35199d by Mattia Rizzolo at 2018-10-12T16:18:49Z
Merge branch 'compare-fat' of salsa.debian.org:marmarek-guest/diffoscope
MR: https://salsa.debian.org/reproducible-builds/diffoscope/merge_requests/13
Signed-off-by: Mattia Rizzolo <mattia at debian.org>
- - - - -
8 changed files:
- debian/tests/control
- diffoscope/comparators/fsimage.py
- tests/comparators/test_fsimage.py
- + tests/data/fat12_expected_diffs
- + tests/data/test1.fat12
- + tests/data/test1.fat16
- + tests/data/test1.fat32
- + tests/data/test2.fat12
Changes:
=====================================
debian/tests/control
=====================================
@@ -2,7 +2,7 @@
# EDIT debian/tests/control.in INSTEAD!
#
Tests: pytest-with-recommends
-Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64], abootimg, acl, 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, gnumeric, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, odt2txt, openssh-client, pgpdump, poppler-utils, procyon-decompiler, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, python3-distro, python3-argcomplete, python3-progressbar, python3-binwalk, python3-defusedxml, python3-guestfs, python3-jsondiff, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
+Depends: diffoscope, python3-pytest, file, linux-image-amd64 [amd64] | linux-image-generic [amd64], abootimg, acl, 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, gnumeric, gnupg, imagemagick, jsbeautifier, libarchive-tools, llvm, lz4 | liblz4-tool, mono-utils, odt2txt, openssh-client, pgpdump, poppler-utils, procyon-decompiler, r-base-core, rpm2cpio, sng, sqlite3, squashfs-tools, tcpdump, unzip, xmlbeans, xxd | vim-common, xz-utils, python3-distro, python3-argcomplete, python3-progressbar, python3-binwalk, python3-defusedxml, python3-guestfs, python3-jsondiff, python3-debian, python3-pyxattr, python3-rpm, python3-tlsh
Tests: pytest
Depends: diffoscope, python3-pytest, file
=====================================
diffoscope/comparators/fsimage.py
=====================================
@@ -77,10 +77,23 @@ class FsImageContainer(Archive):
class FsImageFile(File):
- DESCRIPTION = "ext2/ext3/ext4/btrfs filesystems"
+ DESCRIPTION = "ext2/ext3/ext4/btrfs/fat filesystems"
CONTAINER_CLASS = FsImageContainer
FILE_TYPE_RE = re.compile(r'^(Linux.*filesystem data|BTRFS Filesystem).*')
+ @classmethod
+ def recognizes(cls, file):
+ # Avoid DOS / MBR file type as it generate a lot of false possitives,
+ # manually check "System identifier string" instead
+ with open(file.path, 'rb') as f:
+ f.seek(54)
+ if f.read(8) in (b'FAT12 ', b'FAT16 '):
+ return True
+ f.seek(82)
+ if f.read(8) == b'FAT32 ':
+ return True
+ return super().recognizes(file)
+
def compare_details(self, other, source=None):
differences = []
my_fs = ''
=====================================
tests/comparators/test_fsimage.py
=====================================
@@ -30,6 +30,10 @@ from ..utils.tools import skip_unless_tools_exist, skip_unless_module_exists
img1 = load_fixture('test1.ext4')
img2 = load_fixture('test2.ext4')
+img1_fat12 = load_fixture('test1.fat12')
+img2_fat12 = load_fixture('test2.fat12')
+img1_fat16 = load_fixture('test1.fat16')
+img1_fat32 = load_fixture('test1.fat32')
@pytest.fixture(scope="session")
@@ -55,6 +59,15 @@ def guestfs_tempdir():
def test_identification(img1):
assert isinstance(img1, FsImageFile)
+def test_identification_fat12(img1_fat12):
+ assert isinstance(img1_fat12, FsImageFile)
+
+def test_identification_fat16(img1_fat16):
+ assert isinstance(img1_fat16, FsImageFile)
+
+def test_identification_fat32(img1_fat32):
+ assert isinstance(img1_fat32, FsImageFile)
+
@skip_unless_tools_exist('qemu-img')
@skip_unless_module_exists('guestfs')
@@ -94,3 +107,27 @@ def test_compare_non_existing(monkeypatch, img1, guestfs_tempdir):
difference = img1.compare(MissingFile('/nonexisting', img1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
+
+ at pytest.fixture
+def differences_fat(img1_fat12, img2_fat12, guestfs_tempdir):
+ return img1_fat12.compare(img2_fat12).details
+
+
+ at skip_unless_tools_exist('qemu-img')
+ at skip_unless_module_exists('guestfs')
+def test_differences_fat(differences_fat, guestfs_tempdir):
+ assert differences_fat[0].source1 == 'filetype from file(1)'
+ assert differences_fat[1].source1 == 'test1.fat12.tar'
+ tarinfo = differences_fat[1].details[0]
+ tardiff = differences_fat[1].details[1]
+ assert tarinfo.source1 == 'file list'
+ assert tarinfo.source2 == 'file list'
+ assert tardiff.source1 == './test1.txt'
+ assert tardiff.source2 == './test1.txt'
+ expected_diff = get_data('fat12_expected_diffs')
+ found_diff = differences_fat[0].unified_diff + \
+ tarinfo.unified_diff + \
+ tardiff.unified_diff
+ # workaround for file(1) bug in stretch
+ found_diff = found_diff.replace('32 MB) ,', '32 MB),')
+ assert expected_diff == found_diff
=====================================
tests/data/fat12_expected_diffs
=====================================
@@ -0,0 +1,10 @@
+@@ -1 +1 @@
+-DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 128 (volumes <=32 MB), Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xc345b241, unlabeled, FAT (12 bit)
++DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 128 (volumes <=32 MB), Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xe8941362, unlabeled, FAT (12 bit)
+@@ -1,2 +1,2 @@
+ drwxr-xr-x 0 0 0 0 1970-01-01 00:00:00.000000 ./
+--rwxr-xr-x 0 0 0 6 2018-10-12 12:50:52.000000 ./test1.txt
++-rwxr-xr-x 0 0 0 6 2018-10-12 12:09:26.000000 ./test1.txt
+@@ -1 +1 @@
+-test1
++test2
=====================================
tests/data/test1.fat12
=====================================
Binary files /dev/null and b/tests/data/test1.fat12 differ
=====================================
tests/data/test1.fat16
=====================================
Binary files /dev/null and b/tests/data/test1.fat16 differ
=====================================
tests/data/test1.fat32
=====================================
Binary files /dev/null and b/tests/data/test1.fat32 differ
=====================================
tests/data/test2.fat12
=====================================
Binary files /dev/null and b/tests/data/test2.fat12 differ
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/b90bd2f68ee350ba1a3cfd33b4c4b192b56f64e2...fa35199d9c55eced57c89556fd4455ae2b24804f
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/b90bd2f68ee350ba1a3cfd33b4c4b192b56f64e2...fa35199d9c55eced57c89556fd4455ae2b24804f
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20181012/e576ea70/attachment.html>
More information about the rb-commits
mailing list