Skip to content
Snippets Groups Projects
Commit e5dc438f authored by Ximin Luo's avatar Ximin Luo
Browse files

comparators/deb: Looser matching for .deb archive members. (Closes: #881937)

parent aef3b3d5
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@
# 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
......@@ -88,6 +89,16 @@ class DebContainer(LibarchiveContainer):
return specialize(member.as_container.get_member('content'))
def perform_fuzzy_matching(self, my_members, other_members):
matched = set()
for name1 in my_members.keys():
main, ext = os.path.splitext(name1)
candidates = [name2 for name2 in other_members.keys() - matched
if os.path.splitext(name2)[0] == main]
if len(candidates) == 1:
yield name1, candidates[0], 0
matched.add(candidates[0])
class DebFile(File):
CONTAINER_CLASS = DebContainer
......
......@@ -79,6 +79,9 @@ class Container(object, metaclass=abc.ABCMeta):
for name in filter_excludes(self.get_member_names()):
yield name, self.get_member(name)
def perform_fuzzy_matching(self, my_members, other_members):
return perform_fuzzy_matching(my_members, other_members)
def get_adjusted_members(self):
"""
Returns an iterable of pairs. The key is what is used to match when
......@@ -150,7 +153,7 @@ class Container(object, metaclass=abc.ABCMeta):
for name in both_names:
yield prep_yield(name, name)
for my_name, other_name, score in perform_fuzzy_matching(my_members, other_members):
for my_name, other_name, score in self.perform_fuzzy_matching(my_members, other_members):
comment = "Files similar despite different names" \
" (difference score: {})".format(score)
yield prep_yield(my_name, other_name, comment)
......
......@@ -124,3 +124,15 @@ def test_compare_non_existing(monkeypatch, deb1):
difference = deb1.compare(MissingFile('/nonexisting', deb1))
assert difference.source2 == '/nonexisting'
assert difference.details[-1].source2 == '/dev/null'
bug881937_deb1 = load_fixture('bug881937_1.deb')
bug881937_deb2 = load_fixture('bug881937_2.deb')
def test_compare_different_compression(bug881937_deb1, bug881937_deb2):
difference = bug881937_deb1.compare(bug881937_deb2)
assert difference.details[1].source1 == 'control.tar.gz'
assert difference.details[1].source2 == 'control.tar.xz'
expected_diff = get_data('bug881937_control_expected_diff')
assert difference.details[1].details[2].details[1].unified_diff == expected_diff
File added
File added
@@ -1,16 +1,16 @@
Package: aptitude-robot
-Version: 1.5.2-1
+Version: 1.5.3-1
Architecture: all
Maintainer: Elmar S. Heeb <elmar@heebs.ch>
Installed-Size: 85
Depends: aptitude, libmoo-perl, librun-parts-perl, lsb-base (>= 3.0-6), perl, psmisc
Recommends: perl-doc
-Suggests: needrestart, needrestart-session, apt-listbugs, heirloom-mailx | bsd-mailx | mailx, xymon-client | hobbit-client
+Suggests: needrestart, needrestart-session, apt-listbugs, bsd-mailx | mailx, xymon-client | hobbit-client
Enhances: aptitude
Section: admin
-Priority: extra
+Priority: optional
Homepage: https://github.com/elmar/aptitude-robot
Description: Automate package choice management
Framework to use aptitude for automated package management including
unattended upgrade, installation, removal, hold, etc. Allows you to automate
what you would manually do with aptitude.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment