1 |
Prefer to install a new package rather than to downgrade an |
2 |
installed package. If the installed package should be |
3 |
downgraded due to it being masked, then allow the downgrade. |
4 |
|
5 |
Bug: https://bugs.gentoo.org/635540 |
6 |
--- |
7 |
pym/portage/dep/dep_check.py | 11 ++- |
8 |
.../tests/resolver/test_or_downgrade_installed.py | 97 ++++++++++++++++++++++ |
9 |
2 files changed, 107 insertions(+), 1 deletion(-) |
10 |
create mode 100644 pym/portage/tests/resolver/test_or_downgrade_installed.py |
11 |
|
12 |
diff --git a/pym/portage/dep/dep_check.py b/pym/portage/dep/dep_check.py |
13 |
index 35caecc74..2c69c1c48 100644 |
14 |
--- a/pym/portage/dep/dep_check.py |
15 |
+++ b/pym/portage/dep/dep_check.py |
16 |
@@ -323,8 +323,10 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
17 |
want_update_pkg = trees[myroot].get("want_update_pkg") |
18 |
downgrade_probe = trees[myroot].get("downgrade_probe") |
19 |
vardb = None |
20 |
+ vardb_match_pkgs = None |
21 |
if "vartree" in trees[myroot]: |
22 |
vardb = trees[myroot]["vartree"].dbapi |
23 |
+ vardb_match_pkgs = getattr(vardb, 'match_pkgs', None) |
24 |
if use_binaries: |
25 |
mydbapi = trees[myroot]["bintree"].dbapi |
26 |
else: |
27 |
@@ -355,6 +357,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
28 |
all_use_satisfied = True |
29 |
all_use_unmasked = True |
30 |
conflict_downgrade = False |
31 |
+ installed_downgrade = False |
32 |
slot_atoms = collections.defaultdict(list) |
33 |
slot_map = {} |
34 |
cp_map = {} |
35 |
@@ -419,6 +422,12 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
36 |
avail_pkg = avail_pkg_use |
37 |
avail_slot = Atom("%s:%s" % (atom.cp, avail_pkg.slot)) |
38 |
|
39 |
+ if vardb_match_pkgs is not None: |
40 |
+ inst_pkg = vardb_match_pkgs(avail_slot) |
41 |
+ if (inst_pkg and avail_pkg < inst_pkg[-1] and |
42 |
+ not downgrade_probe(inst_pkg[-1])): |
43 |
+ installed_downgrade = True |
44 |
+ |
45 |
slot_map[avail_slot] = avail_pkg |
46 |
slot_atoms[avail_slot].append(atom) |
47 |
highest_cpv = cp_map.get(avail_pkg.cp) |
48 |
@@ -487,7 +496,7 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
49 |
unsat_use_installed.append(this_choice) |
50 |
else: |
51 |
unsat_use_non_installed.append(this_choice) |
52 |
- elif conflict_downgrade: |
53 |
+ elif conflict_downgrade or installed_downgrade: |
54 |
other.append(this_choice) |
55 |
else: |
56 |
all_in_graph = True |
57 |
diff --git a/pym/portage/tests/resolver/test_or_downgrade_installed.py b/pym/portage/tests/resolver/test_or_downgrade_installed.py |
58 |
new file mode 100644 |
59 |
index 000000000..22307a5bc |
60 |
--- /dev/null |
61 |
+++ b/pym/portage/tests/resolver/test_or_downgrade_installed.py |
62 |
@@ -0,0 +1,97 @@ |
63 |
+# Copyright 2017 Gentoo Foundation |
64 |
+# Distributed under the terms of the GNU General Public License v2 |
65 |
+ |
66 |
+from portage.tests import TestCase |
67 |
+from portage.tests.resolver.ResolverPlayground import ( |
68 |
+ ResolverPlayground, |
69 |
+ ResolverPlaygroundTestCase, |
70 |
+) |
71 |
+ |
72 |
+class OrDowngradeInstalledTestCase(TestCase): |
73 |
+ |
74 |
+ def testOrDowngradeInstalled(self): |
75 |
+ ebuilds = { |
76 |
+ 'net-misc/foo-1': { |
77 |
+ 'EAPI': '6', |
78 |
+ 'RDEPEND': '|| ( sys-libs/glibc[rpc(-)] net-libs/libtirpc )' |
79 |
+ }, |
80 |
+ 'net-libs/libtirpc-1': { |
81 |
+ 'EAPI': '6', |
82 |
+ }, |
83 |
+ 'sys-libs/glibc-2.26': { |
84 |
+ 'EAPI': '6', |
85 |
+ 'IUSE': '' |
86 |
+ }, |
87 |
+ 'sys-libs/glibc-2.24': { |
88 |
+ 'EAPI': '6', |
89 |
+ 'IUSE': '+rpc' |
90 |
+ }, |
91 |
+ } |
92 |
+ |
93 |
+ installed = { |
94 |
+ 'sys-libs/glibc-2.26': { |
95 |
+ 'EAPI': '6', |
96 |
+ 'IUSE': '' |
97 |
+ }, |
98 |
+ } |
99 |
+ |
100 |
+ world = ['sys-libs/glibc'] |
101 |
+ |
102 |
+ test_cases = ( |
103 |
+ # Test bug 635540, where we need to install libtirpc |
104 |
+ # rather than downgrade glibc. |
105 |
+ ResolverPlaygroundTestCase( |
106 |
+ ['net-misc/foo'], |
107 |
+ success=True, |
108 |
+ mergelist=[ |
109 |
+ 'net-libs/libtirpc-1', |
110 |
+ 'net-misc/foo-1', |
111 |
+ ], |
112 |
+ ), |
113 |
+ ) |
114 |
+ |
115 |
+ playground = ResolverPlayground(debug=False, |
116 |
+ ebuilds=ebuilds, installed=installed, world=world) |
117 |
+ |
118 |
+ try: |
119 |
+ for test_case in test_cases: |
120 |
+ playground.run_TestCase(test_case) |
121 |
+ self.assertEqual(test_case.test_success, True, |
122 |
+ test_case.fail_msg) |
123 |
+ finally: |
124 |
+ playground.debug = False |
125 |
+ playground.cleanup() |
126 |
+ |
127 |
+ # In some cases it's necessary to downgrade due to |
128 |
+ # the installed package being masked (glibc is a |
129 |
+ # not an ideal example because it's usually not |
130 |
+ # practical to downgrade it). |
131 |
+ user_config = { |
132 |
+ "package.mask" : ( |
133 |
+ ">=sys-libs/glibc-2.26", |
134 |
+ ), |
135 |
+ } |
136 |
+ |
137 |
+ test_cases = ( |
138 |
+ ResolverPlaygroundTestCase( |
139 |
+ ['net-misc/foo'], |
140 |
+ success=True, |
141 |
+ mergelist=[ |
142 |
+ 'sys-libs/glibc-2.24', |
143 |
+ 'net-misc/foo-1', |
144 |
+ ], |
145 |
+ ), |
146 |
+ ) |
147 |
+ |
148 |
+ playground = ResolverPlayground(debug=False, |
149 |
+ ebuilds=ebuilds, installed=installed, world=world, |
150 |
+ user_config=user_config) |
151 |
+ |
152 |
+ try: |
153 |
+ for test_case in test_cases: |
154 |
+ playground.run_TestCase(test_case) |
155 |
+ self.assertEqual(test_case.test_success, True, |
156 |
+ test_case.fail_msg) |
157 |
+ finally: |
158 |
+ playground.debug = False |
159 |
+ playground.cleanup() |
160 |
-- |
161 |
2.13.5 |