1 |
Prefer to install a new package in order to allow upgrade of an |
2 |
installed package. This generalizes the code from bug 635540 so |
3 |
that it both allows desirable upgrades and prevents unwanted |
4 |
downgrades. |
5 |
|
6 |
Fixes: 7c58e3737616 ("dep_zapdeps: install new package, avoid downgrade (bug 635540)") |
7 |
Bug: https://bugs.gentoo.org/643974 |
8 |
--- |
9 |
pym/portage/dep/dep_check.py | 11 ++- |
10 |
.../tests/resolver/test_or_upgrade_installed.py | 94 ++++++++++++++++++++++ |
11 |
2 files changed, 99 insertions(+), 6 deletions(-) |
12 |
create mode 100644 pym/portage/tests/resolver/test_or_upgrade_installed.py |
13 |
|
14 |
diff --git a/pym/portage/dep/dep_check.py b/pym/portage/dep/dep_check.py |
15 |
index 2bb9dc339..291626f56 100644 |
16 |
--- a/pym/portage/dep/dep_check.py |
17 |
+++ b/pym/portage/dep/dep_check.py |
18 |
@@ -366,10 +366,8 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
19 |
want_update_pkg = trees[myroot].get("want_update_pkg") |
20 |
downgrade_probe = trees[myroot].get("downgrade_probe") |
21 |
vardb = None |
22 |
- vardb_match_pkgs = None |
23 |
if "vartree" in trees[myroot]: |
24 |
vardb = trees[myroot]["vartree"].dbapi |
25 |
- vardb_match_pkgs = getattr(vardb, 'match_pkgs', None) |
26 |
if use_binaries: |
27 |
mydbapi = trees[myroot]["bintree"].dbapi |
28 |
else: |
29 |
@@ -465,10 +463,11 @@ def dep_zapdeps(unreduced, reduced, myroot, use_binaries=0, trees=None): |
30 |
avail_pkg = avail_pkg_use |
31 |
avail_slot = Atom("%s:%s" % (atom.cp, avail_pkg.slot)) |
32 |
|
33 |
- if vardb_match_pkgs is not None and downgrade_probe is not None: |
34 |
- inst_pkg = vardb_match_pkgs(avail_slot) |
35 |
- if (inst_pkg and avail_pkg < inst_pkg[-1] and |
36 |
- not downgrade_probe(inst_pkg[-1])): |
37 |
+ if downgrade_probe is not None: |
38 |
+ highest_in_slot = mydbapi_match_pkgs(avail_slot) |
39 |
+ if (avail_pkg and highest_in_slot and |
40 |
+ avail_pkg < highest_in_slot[-1] and |
41 |
+ not downgrade_probe(avail_pkg)): |
42 |
installed_downgrade = True |
43 |
|
44 |
slot_map[avail_slot] = avail_pkg |
45 |
diff --git a/pym/portage/tests/resolver/test_or_upgrade_installed.py b/pym/portage/tests/resolver/test_or_upgrade_installed.py |
46 |
new file mode 100644 |
47 |
index 000000000..70703a614 |
48 |
--- /dev/null |
49 |
+++ b/pym/portage/tests/resolver/test_or_upgrade_installed.py |
50 |
@@ -0,0 +1,94 @@ |
51 |
+# Copyright 2018 Gentoo Foundation |
52 |
+# Distributed under the terms of the GNU General Public License v2 |
53 |
+ |
54 |
+from portage.tests import TestCase |
55 |
+from portage.tests.resolver.ResolverPlayground import ( |
56 |
+ ResolverPlayground, |
57 |
+ ResolverPlaygroundTestCase, |
58 |
+) |
59 |
+ |
60 |
+class OrUpgradeInstalledTestCase(TestCase): |
61 |
+ |
62 |
+ def testOrUpgradeInstalled(self): |
63 |
+ ebuilds = { |
64 |
+ 'net-misc/foo-1': { |
65 |
+ 'EAPI': '6', |
66 |
+ 'RDEPEND': '|| ( sys-libs/glibc[rpc(-)] net-libs/libtirpc )' |
67 |
+ }, |
68 |
+ 'net-libs/libtirpc-1': { |
69 |
+ 'EAPI': '6', |
70 |
+ }, |
71 |
+ 'sys-libs/glibc-2.26': { |
72 |
+ 'EAPI': '6', |
73 |
+ 'IUSE': '' |
74 |
+ }, |
75 |
+ 'sys-libs/glibc-2.24': { |
76 |
+ 'EAPI': '6', |
77 |
+ 'IUSE': '+rpc' |
78 |
+ }, |
79 |
+ } |
80 |
+ |
81 |
+ installed = { |
82 |
+ 'sys-libs/glibc-2.24': { |
83 |
+ 'EAPI': '6', |
84 |
+ 'IUSE': '+rpc', |
85 |
+ 'USE': 'rpc', |
86 |
+ }, |
87 |
+ } |
88 |
+ |
89 |
+ world = ['sys-libs/glibc'] |
90 |
+ |
91 |
+ test_cases = ( |
92 |
+ # Test bug 643974, where we need to install libtirpc |
93 |
+ # in order to upgrade glibc. |
94 |
+ ResolverPlaygroundTestCase( |
95 |
+ ['net-misc/foo', '@world'], |
96 |
+ options={'--update': True, '--deep': True}, |
97 |
+ success=True, |
98 |
+ mergelist=['net-libs/libtirpc-1', 'sys-libs/glibc-2.26', 'net-misc/foo-1'] |
99 |
+ ), |
100 |
+ ) |
101 |
+ |
102 |
+ playground = ResolverPlayground(debug=False, |
103 |
+ ebuilds=ebuilds, installed=installed, world=world) |
104 |
+ |
105 |
+ try: |
106 |
+ for test_case in test_cases: |
107 |
+ playground.run_TestCase(test_case) |
108 |
+ self.assertEqual(test_case.test_success, True, |
109 |
+ test_case.fail_msg) |
110 |
+ finally: |
111 |
+ playground.debug = False |
112 |
+ playground.cleanup() |
113 |
+ |
114 |
+ # In some cases it's necessary to avoid upgrade due to |
115 |
+ # the package being masked. |
116 |
+ user_config = { |
117 |
+ "package.mask" : ( |
118 |
+ ">=sys-libs/glibc-2.26", |
119 |
+ ), |
120 |
+ } |
121 |
+ |
122 |
+ test_cases = ( |
123 |
+ ResolverPlaygroundTestCase( |
124 |
+ ['net-misc/foo', '@world'], |
125 |
+ options={'--update': True, '--deep': True}, |
126 |
+ success=True, |
127 |
+ mergelist=[ |
128 |
+ 'net-misc/foo-1', |
129 |
+ ] |
130 |
+ ), |
131 |
+ ) |
132 |
+ |
133 |
+ playground = ResolverPlayground(debug=False, |
134 |
+ ebuilds=ebuilds, installed=installed, world=world, |
135 |
+ user_config=user_config) |
136 |
+ |
137 |
+ try: |
138 |
+ for test_case in test_cases: |
139 |
+ playground.run_TestCase(test_case) |
140 |
+ self.assertEqual(test_case.test_success, True, |
141 |
+ test_case.fail_msg) |
142 |
+ finally: |
143 |
+ playground.debug = False |
144 |
+ playground.cleanup() |
145 |
-- |
146 |
2.13.6 |