1 |
Since commit d800d224ab38c0f524d3fe858ebe201cbfa903c1, emerge --search |
2 |
could randomly report incorrect results for the installed version |
3 |
due to the replaced version of a given slot remaining in the cache. |
4 |
|
5 |
Fixes: d800d224ab38 ("Log changes between vdb_metadata.pickle updates") |
6 |
X-Gentoo-Bug: 547532 |
7 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=547532 |
8 |
--- |
9 |
pym/_emerge/search.py | 10 ++++++++-- |
10 |
pym/portage/dbapi/_VdbMetadataDelta.py | 22 +++++++++++++++++++++- |
11 |
2 files changed, 29 insertions(+), 3 deletions(-) |
12 |
|
13 |
diff --git a/pym/_emerge/search.py b/pym/_emerge/search.py |
14 |
index e7f6f44..5a8143c 100644 |
15 |
--- a/pym/_emerge/search.py |
16 |
+++ b/pym/_emerge/search.py |
17 |
@@ -1,4 +1,4 @@ |
18 |
-# Copyright 1999-2014 Gentoo Foundation |
19 |
+# Copyright 1999-2015 Gentoo Foundation |
20 |
# Distributed under the terms of the GNU General Public License v2 |
21 |
|
22 |
from __future__ import unicode_literals |
23 |
@@ -442,7 +442,13 @@ class search(object): |
24 |
def getInstallationStatus(self,package): |
25 |
installed_package = self._vardb.match(package) |
26 |
if installed_package: |
27 |
- installed_package = installed_package[-1] |
28 |
+ try: |
29 |
+ self._vardb.match_unordered |
30 |
+ except AttributeError: |
31 |
+ installed_package = installed_package[-1] |
32 |
+ else: |
33 |
+ installed_package = portage.best(installed_package) |
34 |
+ |
35 |
else: |
36 |
installed_package = "" |
37 |
result = "" |
38 |
diff --git a/pym/portage/dbapi/_VdbMetadataDelta.py b/pym/portage/dbapi/_VdbMetadataDelta.py |
39 |
index 3e3ff18..2dbb07a 100644 |
40 |
--- a/pym/portage/dbapi/_VdbMetadataDelta.py |
41 |
+++ b/pym/portage/dbapi/_VdbMetadataDelta.py |
42 |
@@ -1,4 +1,4 @@ |
43 |
-# Copyright 2014 Gentoo Foundation |
44 |
+# Copyright 2014-2015 Gentoo Foundation |
45 |
# Distributed under the terms of the GNU General Public License v2 |
46 |
|
47 |
import errno |
48 |
@@ -8,6 +8,7 @@ import os |
49 |
|
50 |
from portage import _encodings |
51 |
from portage.util import atomic_ofstream |
52 |
+from portage.versions import cpv_getkey |
53 |
|
54 |
class VdbMetadataDelta(object): |
55 |
|
56 |
@@ -138,10 +139,12 @@ class VdbMetadataDelta(object): |
57 |
|
58 |
def applyDelta(self, data): |
59 |
packages = self._vardb._aux_cache["packages"] |
60 |
+ added_slots = {} |
61 |
for delta in data["deltas"]: |
62 |
cpv = delta["package"] + "-" + delta["version"] |
63 |
event = delta["event"] |
64 |
if event == "add": |
65 |
+ added_slots[cpv] = delta |
66 |
# Use aux_get to populate the cache |
67 |
# for this cpv. |
68 |
if cpv not in packages: |
69 |
@@ -151,3 +154,20 @@ class VdbMetadataDelta(object): |
70 |
pass |
71 |
elif event == "remove": |
72 |
packages.pop(cpv, None) |
73 |
+ |
74 |
+ # Remove replaced versions from updated slots |
75 |
+ for cached_cpv, (mtime, metadata) in list(packages.items()): |
76 |
+ if cached_cpv in added_slots: |
77 |
+ continue |
78 |
+ replaced = False |
79 |
+ for cpv, delta in added_slots.items(): |
80 |
+ if (cached_cpv.startswith(delta["package"]) and |
81 |
+ metadata.get("SLOT") == delta["slot"] and |
82 |
+ cpv_getkey(cached_cpv) == delta["package"]): |
83 |
+ replaced = True |
84 |
+ break |
85 |
+ if replaced: |
86 |
+ del packages[cached_cpv] |
87 |
+ del added_slots[cpv] |
88 |
+ if not added_slots: |
89 |
+ break |
90 |
-- |
91 |
2.3.5 |