Gentoo Archives: gentoo-commits

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