[Git][reproducible-builds/diffoscope][master] 5 commits: We don't use the "logging" variable here, so alias it to "_" instead.

Chris Lamb (@lamby) gitlab at salsa.debian.org
Tue Aug 17 11:01:19 UTC 2021



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
f7f4039d by Chris Lamb at 2021-08-17T11:14:01+01:00
We don't use the "logging" variable here, so alias it to "_" instead.

- - - - -
ee10baf8 by Chris Lamb at 2021-08-17T12:01:00+01:00
Update some various copyright years.

- - - - -
21a7d8c7 by Chris Lamb at 2021-08-17T12:01:00+01:00
Include profiling information in --debug output if --profile is not set.

- - - - -
80df0f6d by Chris Lamb at 2021-08-17T12:01:00+01:00
Don't print an orphan newline when the Black source code formatter self-test passes.

- - - - -
778fa799 by Chris Lamb at 2021-08-17T12:01:00+01:00
Add a special-case to squshfs image extraction to not fail if we are not root. (Closes: Debian:#991059)

Don't treat a failure to extract all entries from squashfs images as a failure that requires falling back to xxd(1) --

- - - - -


11 changed files:

- diffoscope/comparators/elf.py
- diffoscope/comparators/odt.py
- diffoscope/comparators/squashfs.py
- diffoscope/main.py
- diffoscope/profiling.py
- tests/comparators/test_odt.py
- tests/comparators/test_squashfs.py
- + tests/data/squashfs_root_expected_diff
- + tests/data/test1_root.squashfs
- + tests/data/test2_root.squashfs
- tests/test_source.py


Changes:

=====================================
diffoscope/comparators/elf.py
=====================================
@@ -2,7 +2,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
-# Copyright © 2015-2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2015-2021 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by


=====================================
diffoscope/comparators/odt.py
=====================================
@@ -1,7 +1,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2017-2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2017-2021 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by


=====================================
diffoscope/comparators/squashfs.py
=====================================
@@ -35,7 +35,7 @@ from .device import Device
 from .symlink import Symlink
 from .directory import Directory
 from .utils.archive import Archive, ArchiveMember
-from .utils.command import Command, our_check_output
+from .utils.command import Command
 
 logger = logging.getLogger(__name__)
 
@@ -260,20 +260,47 @@ class SquashfsContainer(Archive):
 
         logger.debug("Extracting %s to %s", self.source.path, self._temp_dir)
 
-        output = our_check_output(
-            (
-                "unsquashfs",
-                "-n",
-                "-f",
-                "-no",
-                "-li",
-                "-d",
-                ".",
-                os.path.abspath(self.source.path),
-            ),
+        cmd = (
+            "unsquashfs",
+            "-n",
+            "-f",
+            "-no",
+            "-li",
+            "-d",
+            ".",
+            os.path.abspath(self.source.path),
+        )
+
+        p = subprocess.Popen(
+            cmd,
+            stdout=subprocess.PIPE,
             stderr=subprocess.PIPE,
             cwd=self._temp_dir,
         )
+        output, stderr = p.communicate()
+
+        if p.returncode != 0:
+            # unsquashfs(1) exits with 1 (with a suitable logging messages that
+            # we can check for) if it could not extract, for example, character
+            # devices that require superuser privileges. In this case, don't
+            # treat this as a failure that requires reverting to xxd(1), but do
+            # let the user know via a comment.
+            if (
+                p.returncode == 1
+                and b"because you're not superuser" in stderr
+                and b"\n\ncreated " in output
+            ):
+                logger.debug("Ignoring unsquashfs return code")
+
+                self.source.add_comment(
+                    "Differences may be incomplete: {}".format(
+                        stderr.decode("utf-8")
+                    )
+                )
+            else:
+                raise subprocess.CalledProcessError(
+                    p.returncode, cmd, output, stderr
+                )
 
         output = iter(output.decode("utf-8").rstrip("\n").split("\n"))
 


=====================================
diffoscope/main.py
=====================================
@@ -739,9 +739,8 @@ def main(args=None):
 
         log_handler = ProgressManager().setup(parsed_args)
 
-        with setup_logging(parsed_args.debug, log_handler) as logger:
+        with setup_logging(parsed_args.debug, log_handler) as _:
             post_parse(parsed_args)
-
             # Call main entry point
             sys.exit(run_diffoscope(parsed_args))
 


=====================================
diffoscope/profiling.py
=====================================
@@ -1,7 +1,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016-2017, 2019-2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2016-2017, 2019-2021 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@ import contextlib
 import collections
 
 from .utils import format_class
+from .logging import setup_logging
 
 _ENABLED = False
 
@@ -50,7 +51,7 @@ class ProfileManager:
 
     def setup(self, parsed_args):
         global _ENABLED
-        _ENABLED = parsed_args.profile_output is not None
+        _ENABLED = parsed_args.profile_output is not None or parsed_args.debug
 
     def increment(self, start, namespace, key):
         if not isinstance(key, str):
@@ -62,11 +63,13 @@ class ProfileManager:
     def finish(self, parsed_args):
         from .presenters.utils import make_printer
 
+        # Include profiling in --debug output if --profile is not set.
         if parsed_args.profile_output is None:
-            return
-
-        with make_printer(parsed_args.profile_output) as fn:
-            self.output(fn)
+            with setup_logging(parsed_args.debug, None) as logger:
+                self.output(lambda x: logger.debug(x.strip("\n")))
+        else:
+            with make_printer(parsed_args.profile_output) as fn:
+                self.output(fn)
 
     def output(self, print_fn):
         title = "# Profiling output for: {}".format(" ".join(sys.argv))


=====================================
tests/comparators/test_odt.py
=====================================
@@ -1,7 +1,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2017, 2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2017, 2020-2021 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by


=====================================
tests/comparators/test_squashfs.py
=====================================
@@ -2,7 +2,7 @@
 # diffoscope: in-depth comparison of files, archives, and directories
 #
 # Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
-# Copyright © 2015-2017, 2019-2020 Chris Lamb <lamby at debian.org>
+# Copyright © 2015-2017, 2019-2021 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,7 +22,7 @@ import subprocess
 
 from diffoscope.comparators.squashfs import SquashfsFile
 
-from ..utils.data import load_fixture, get_data
+from ..utils.data import load_fixture, assert_diff
 from ..utils.tools import skip_unless_tools_exist, skip_unless_tool_is_at_least
 from ..utils.nonexisting import assert_non_existing
 
@@ -63,25 +63,38 @@ def differences(squashfs1, squashfs2):
 
 @skip_unless_tool_is_at_least("unsquashfs", unsquashfs_version, "4.4")
 def test_superblock(differences):
-    expected_diff = get_data("squashfs_superblock_expected_diff")
-    assert differences[0].unified_diff == expected_diff
+    assert_diff(differences[0], "squashfs_superblock_expected_diff")
 
 
 @skip_unless_tools_exist("unsquashfs")
 def test_symlink(differences):
     assert differences[2].comment == "symlink"
-    expected_diff = get_data("symlink_expected_diff")
-    assert differences[2].unified_diff == expected_diff
+    assert_diff(differences[2], "symlink_expected_diff")
 
 
 @skip_unless_tools_exist("unsquashfs")
 def test_compressed_files(differences):
     assert differences[3].source1 == "/text"
     assert differences[3].source2 == "/text"
-    expected_diff = get_data("text_ascii_expected_diff")
-    assert differences[3].unified_diff == expected_diff
+    assert_diff(differences[3], "text_ascii_expected_diff")
 
 
 @skip_unless_tools_exist("unsquashfs")
 def test_compare_non_existing(monkeypatch, squashfs1):
     assert_non_existing(monkeypatch, squashfs1)
+
+
+# Test things that require root
+
+squashfs1_root = load_fixture("test1_root.squashfs")
+squashfs2_root = load_fixture("test2_root.squashfs")
+
+
+ at pytest.fixture
+def differences_root(squashfs1_root, squashfs2_root):
+    return squashfs1_root.compare(squashfs2_root).details
+
+
+ at skip_unless_tools_exist("unsquashfs")
+def test_symlink_root(differences_root):
+    assert_diff(differences_root[1], "squashfs_root_expected_diff")


=====================================
tests/data/squashfs_root_expected_diff
=====================================
@@ -0,0 +1,11 @@
+@@ -1,7 +1,7 @@
+ Parallel unsquashfs: Using 8 processors
+ 3 inodes (3 blocks) to write
+ 
+-drwxr-xr-x lamby/lamby              51 2015-06-24 14:47 
+-lrwxrwxrwx lamby/lamby               6 2015-06-24 14:47 /link -> broken
++drwxr-xr-x lamby/lamby              51 2015-06-24 14:50 
++lrwxrwxrwx lamby/lamby              13 2015-06-24 14:50 /link -> really-broken
+ crw-r--r-- root/root             1,  3 2015-06-24 14:47 /null
+--rw-r--r-- lamby/lamby             446 2015-06-24 14:49 /text
++-rw-r--r-- lamby/lamby             671 2015-06-24 14:49 /text


=====================================
tests/data/test1_root.squashfs
=====================================
Binary files /dev/null and b/tests/data/test1_root.squashfs differ


=====================================
tests/data/test2_root.squashfs
=====================================
Binary files /dev/null and b/tests/data/test2_root.squashfs differ


=====================================
tests/test_source.py
=====================================
@@ -135,6 +135,7 @@ ALLOWED_TEST_FILES = {
     "test1.rpm",
     "test1.sqlite3",
     "test1.squashfs",
+    "test1_root.squashfs",
     "test1.tar",
     "test1.xml",
     "test1.xsb",
@@ -195,6 +196,7 @@ ALLOWED_TEST_FILES = {
     "test2.rpm",
     "test2.sqlite3",
     "test2.squashfs",
+    "test2_root.squashfs",
     "test2.tar",
     "test2.xml",
     "test2.xsb",
@@ -250,7 +252,8 @@ def test_code_is_black_clean():
     ).decode("utf-8")
 
     # Display diff in "captured stdout call"
-    print(output)
+    if output:
+        print(output)
 
     assert not output, output
 



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/38ec13ecc5f69a0a7f28af931e348517817d78a6...778fa7991ec3537d86f33a9ad6aec73463b49df3

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/38ec13ecc5f69a0a7f28af931e348517817d78a6...778fa7991ec3537d86f33a9ad6aec73463b49df3
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/20210817/969bbc1f/attachment.htm>


More information about the rb-commits mailing list