Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] binarytree._read_metadata: return empty strings for undefine values (bug 603826)
Date: Wed, 28 Dec 2016 00:04:00
Message-Id: 566969fe-e219-e39c-a6f6-016e8164370f@gentoo.org
In Reply to: Re: [gentoo-portage-dev] [PATCH] binarytree._read_metadata: return empty strings for undefine values (bug 603826) by Brian Dolbec
1 On 12/27/2016 03:39 PM, Brian Dolbec wrote:
2 > On Tue, 27 Dec 2016 13:33:55 -0800
3 > Zac Medico <zmedico@g.o> wrote:
4 >
5 >> Fix the binarytree._read_metadata method to return empty strings for
6 >> undefined metadata values, in order to fulfill a contract with the
7 >> _pkg_str class. This prevents an AttributeError triggered by old
8 >> binary packages which have undefined repository metadata, as reported
9 >> in bug 603826.
10 >>
11 >> X-Gentoo-bug: 603826
12 >> X-Gentoo-bug-url: https://bugs.gentoo.org/603826
13 >> ---
14 >> pym/portage/dbapi/bintree.py | 31 +++++++++++++++++++++++++------
15 >> pym/portage/versions.py | 8 +++++++-
16 >> 2 files changed, 32 insertions(+), 7 deletions(-)
17 >>
18 >> diff --git a/pym/portage/dbapi/bintree.py
19 >> b/pym/portage/dbapi/bintree.py index f483059..3341889 100644
20 >> --- a/pym/portage/dbapi/bintree.py
21 >> +++ b/pym/portage/dbapi/bintree.py
22 >> @@ -1,4 +1,4 @@
23 >> -# Copyright 1998-2014 Gentoo Foundation
24 >> +# Copyright 1998-2016 Gentoo Foundation
25 >> # Distributed under the terms of the GNU General Public License v2
26 >>
27 >> from __future__ import unicode_literals
28 >> @@ -1041,12 +1041,12 @@ class binarytree(object):
29 >> noiselevel=-1)
30 >> return
31 >> metadata = self._read_metadata(full_path, s)
32 >> - slot = metadata.get("SLOT")
33 >> + invalid_depend = False
34 >> try:
35 >> self._eval_use_flags(cpv, metadata)
36 >> except portage.exception.InvalidDependString:
37 >> - slot = None
38 >> - if slot is None:
39 >> + invalid_depend = True
40 >> + if invalid_depend or not metadata.get("SLOT"):
41 >> writemsg(_("!!! Invalid binary package:
42 >> '%s'\n") % full_path, noiselevel=-1)
43 >> return
44 >> @@ -1126,6 +1126,21 @@ class binarytree(object):
45 >> return cpv
46 >>
47 >> def _read_metadata(self, filename, st, keys=None):
48 >> + """
49 >> + Read metadata from a binary package. The returned
50 >> metadata
51 >> + dictionary will contain empty strings for any values
52 >> that
53 >> + are undefined (this is important because the
54 >> _pkg_str class
55 >> + distinguishes between missing and undefined values).
56 >> +
57 >> + @param filename: File path of the binary package
58 >> + @type filename: string
59 >> + @param st: stat result for the binary package
60 >> + @type st: os.stat_result
61 >> + @param keys: optional list of specific metadata keys
62 >> to retrieve
63 >> + @type keys: iterable
64 >> + @rtype: dict
65 >> + @return: package metadata
66 >> + """
67 >> if keys is None:
68 >> keys = self.dbapi._aux_cache_keys
69 >> metadata = self.dbapi._aux_cache_slot_dict()
70 >> @@ -1139,10 +1154,14 @@ class binarytree(object):
71 >> metadata[k] = _unicode(st.st_size)
72 >> else:
73 >> v =
74 >> binary_metadata.get(_unicode_encode(k))
75 >> - if v is not None:
76 >> + if v is None:
77 >> + if k == "EAPI":
78 >> + metadata[k] = "0"
79 >> + else:
80 >> + metadata[k] = ""
81 >> + else:
82 >> v = _unicode_decode(v)
83 >> metadata[k] = "
84 >> ".join(v.split())
85 >> - metadata.setdefault("EAPI", "0")
86 >> return metadata
87 >>
88 >> def _inject_file(self, pkgindex, cpv, filename):
89 >> diff --git a/pym/portage/versions.py b/pym/portage/versions.py
90 >> index a028d93..adfb1c3 100644
91 >> --- a/pym/portage/versions.py
92 >> +++ b/pym/portage/versions.py
93 >> @@ -1,5 +1,5 @@
94 >> # versions.py -- core Portage functionality
95 >> -# Copyright 1998-2014 Gentoo Foundation
96 >> +# Copyright 1998-2016 Gentoo Foundation
97 >> # Distributed under the terms of the GNU General Public License v2
98 >>
99 >> from __future__ import unicode_literals
100 >> @@ -359,6 +359,12 @@ class _pkg_str(_unicode):
101 >> Instances are typically created in dbapi.cp_list() or the
102 >> Atom contructor, and propagate from there. Generally, code that
103 >> pickles these objects will manually convert them to a plain unicode
104 >> object first. +
105 >> + Instances of this class will have missing attributes for
106 >> metadata that
107 >> + has not been passed into the constructor. The missing
108 >> attributes are
109 >> + used to distinguish missing metadata values from undefined
110 >> metadata values.
111 >> + For example, the repo attribute will be missing if the
112 >> 'repository' key
113 >> + is missing from the metadata dictionary.
114 >> """
115 >>
116 >> def __new__(cls, cpv, metadata=None, settings=None,
117 >> eapi=None,
118 >
119 > LGTM
120 >
121
122 Thanks, pushed:
123
124 https://gitweb.gentoo.org/proj/portage.git/commit/?id=67109fe41df07c9fa0e588b81f37ff61a71470f6
125
126 --
127 Thanks,
128 Zac