Skip to content
Commits on Source (3)
......@@ -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
......
......@@ -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 = ''
......
......@@ -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'
@pytest.fixture
def differences_fat(img1_fat12, img2_fat12, guestfs_tempdir):
return img1_fat12.compare(img2_fat12).details
@skip_unless_tools_exist('qemu-img')
@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
@@ -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