[Git][reproducible-builds/diffoscope][master] 4 commits: comparators: add 'asar' support
Chris Lamb (@lamby)
gitlab at salsa.debian.org
Mon Jan 27 10:41:28 UTC 2025
Chris Lamb pushed to branch master at Reproducible Builds / diffoscope
Commits:
01f0189b by fridtjof at 2025-01-27T10:40:33+00:00
comparators: add 'asar' support
- - - - -
b8b99410 by fridtjof at 2025-01-27T10:40:38+00:00
external_tools: add asar
- - - - -
92a2e60e by fridtjof at 2025-01-27T10:40:38+00:00
tests: add asar comparator
- - - - -
5f3df08f by Chris Lamb at 2025-01-27T10:40:38+00:00
Drop unused subprocess import.
- - - - -
6 changed files:
- diffoscope/comparators/__init__.py
- + diffoscope/comparators/asar.py
- diffoscope/external_tools.py
- + tests/comparators/test_asar.py
- + tests/data/test1.asar
- + tests/data/test2.asar
Changes:
=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -125,6 +125,7 @@ class ComparatorManager:
("vmlinuz.VmlinuzFile",),
("arsc.ArscFile",),
("xar.XarFile",),
+ ("asar.AsarFile",),
)
_singleton = {}
=====================================
diffoscope/comparators/asar.py
=====================================
@@ -0,0 +1,84 @@
+#
+# 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>
+#
+# diffoscope is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+
+import os
+import re
+import logging
+
+from diffoscope.tools import tool_required
+from diffoscope.tempfiles import get_temporary_directory
+
+from .utils.file import File
+from .utils.archive import Archive
+from .utils.command import our_check_output
+
+logger = logging.getLogger(__name__)
+
+
+class AsarContainer(Archive):
+ @tool_required("asar")
+ def open_archive(self):
+ # Just extract the asar as a whole due to the problems mentioned below
+ self._members = []
+ self._unpacked = get_temporary_directory(suffix="asar")
+
+ logger.debug("Extracting asar to %s", self._unpacked.name)
+
+ our_check_output(
+ [
+ "asar",
+ "extract",
+ os.path.abspath(self.source.path),
+ self._unpacked.name,
+ ],
+ cwd=self._unpacked.name,
+ )
+
+ for root, _, files in os.walk(self._unpacked.name):
+ current_dir = []
+
+ for filename in sorted(files):
+ abspath = os.path.join(root, filename)
+
+ relpath = abspath[len(self._unpacked.name) + 1 :]
+
+ current_dir.append(relpath)
+
+ self._members.extend(current_dir)
+
+ return self
+
+ def close_archive(self):
+ self._unpacked.cleanup()
+
+ def get_member_names(self):
+ # 'asar list' returns all entries including directories, so it's hard to use
+ # rely on extraction to temp directory instead
+ return self._members
+
+ def extract(self, member_name, dest_dir):
+ # while 'asar' lets us extract single files, it does not let us specify where to output them at all.
+ # rely on extraction to temp directory instead
+ return os.path.join(self._unpacked.name, member_name)
+
+
+class AsarFile(File):
+ DESCRIPTION = "asar archives"
+ CONTAINER_CLASSES = [AsarContainer]
+ FILE_TYPE_RE = re.compile(r"^\bElectron ASAR archive\b")
=====================================
diffoscope/external_tools.py
=====================================
@@ -30,6 +30,7 @@ EXTERNAL_TOOLS = {
"apksigcopier": {"debian": "apksigcopier"},
"apktool": {"debian": "apktool"},
"apksigner": {"debian": "apksigner"},
+ "asar": {"arch": "asar"},
"db_dump": {"debian": "db-util", "guix": "bdb"},
"bsdtar": {
"debian": "libarchive-tools",
=====================================
tests/comparators/test_asar.py
=====================================
@@ -0,0 +1,54 @@
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2015-2017, 2020 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with diffoscope. If not, see <https://www.gnu.org/licenses/>.
+
+import pytest
+
+from diffoscope.config import Config
+from diffoscope.comparators.asar import AsarFile
+from diffoscope.comparators.missing_file import MissingFile
+
+from ..utils.data import load_fixture, get_data
+from ..utils.tools import skip_unless_tools_exist
+from ..utils.nonexisting import assert_non_existing
+
+
+asar1 = load_fixture("test1.asar")
+asar2 = load_fixture("test2.asar")
+
+
+def test_identification(asar1):
+ assert isinstance(asar1, AsarFile)
+
+
+def test_no_differences(asar1):
+ difference = asar1.compare(asar1)
+ assert difference is None
+
+
+ at pytest.fixture
+def differences(asar1, asar2):
+ return asar1.compare(asar2).details
+
+
+ at skip_unless_tools_exist("asar")
+def test_text_file(differences):
+ assert differences[0].source1 == "dir/text"
+ assert differences[0].source2 == "dir/text"
+ expected_diff = get_data("text_ascii_expected_diff")
+ assert differences[0].unified_diff == expected_diff
=====================================
tests/data/test1.asar
=====================================
Binary files /dev/null and b/tests/data/test1.asar differ
=====================================
tests/data/test2.asar
=====================================
Binary files /dev/null and b/tests/data/test2.asar differ
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/e49a16f77058d08915cf7cea86f8c15c43ca9789...5f3df08f9110871bf22ddfc947f37416b52b57ba
--
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/e49a16f77058d08915cf7cea86f8c15c43ca9789...5f3df08f9110871bf22ddfc947f37416b52b57ba
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/20250127/2215da20/attachment.htm>
More information about the rb-commits
mailing list