Browse Source

packages_tree: exact match trumps other providers

Ubuntu frequently has multiple providers for the same package name,
e.g. "vim" is provided by "vim", "vim-gnome" etc.

We need to adjust the resolving algorithm to:
1. lookup in virtual packages
2. lookup in packages
3. lookup in obsoletes.
Use the package which was found last (version-sorted).

Closes-bug: 1656888

Change-Id: I7279aa6526ff9133829be2e316932c9b052c7814
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
Alexandru Avadanii 2 years ago
parent
commit
25b8673f84
1 changed files with 17 additions and 11 deletions
  1. 17
    11
      packetary/objects/packages_tree.py

+ 17
- 11
packetary/objects/packages_tree.py View File

@@ -68,25 +68,31 @@ class PackagesTree(object):
68 68
         :param version_range: the range of versions.
69 69
         :return: the list of suitable packages
70 70
         """
71
-        candidates = set()
72
-        # find package by name
73
-        if name in self.packages:
74
-            candidates.update(self.packages.find_all(name, version_range))
71
+        candidates = []
75 72
 
76 73
         # find package by provides
77 74
         # in case of rpm:
78 75
         #    set(candidates) >= set(provides)
79 76
         if name in self.provides:
80
-            candidates.update(self._resolve_relation(
81
-                self.provides[name], version_range)
82
-            )
77
+            candidates.extend(sorted(
78
+                self._resolve_relation(self.provides[name], version_range),
79
+                key=lambda x: x.version
80
+            ))
81
+
82
+        # find package by name
83
+        if name in self.packages:
84
+            candidates.extend(sorted(
85
+                self.packages.find_all(name, version_range),
86
+                key=lambda x: x.version
87
+            ))
83 88
 
84 89
         if name in self.obsoletes:
85
-            candidates.update(self._resolve_relation(
86
-                self.obsoletes[name], version_range)
87
-            )
90
+            candidates.extend(sorted(
91
+                self._resolve_relation(self.obsoletes[name], version_range),
92
+                key=lambda x: x.version
93
+            ))
88 94
 
89
-        return sorted(candidates, key=lambda x: x.version)
95
+        return candidates
90 96
 
91 97
     def get_unresolved_dependencies(self):
92 98
         """Gets the set of unresolved dependencies.

Loading…
Cancel
Save