From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/
Date: Wed, 28 Dec 2016 00:01:20 +0000 (UTC) [thread overview]
Message-ID: <1482882551.67109fe41df07c9fa0e588b81f37ff61a71470f6.zmedico@gentoo> (raw)
commit: 67109fe41df07c9fa0e588b81f37ff61a71470f6
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Dec 27 20:29:11 2016 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Dec 27 23:49:11 2016 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=67109fe4
binarytree._read_metadata: return empty strings for undefined values (bug 603826)
Fix the binarytree._read_metadata method to return empty strings for
undefined metadata values, in order to fulfill a contract with the
_pkg_str class. This prevents an AttributeError triggered by old
binary packages which have undefined repository metadata, as reported
in bug 603826.
X-Gentoo-bug: 603826
X-Gentoo-bug-url: https://bugs.gentoo.org/603826
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>
pym/portage/dbapi/bintree.py | 33 ++++++++++++++++++++++++++-------
pym/portage/versions.py | 8 +++++++-
2 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
index f483059..ae9e7ca 100644
--- a/pym/portage/dbapi/bintree.py
+++ b/pym/portage/dbapi/bintree.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2014 Gentoo Foundation
+# Copyright 1998-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import unicode_literals
@@ -743,7 +743,7 @@ class binarytree(object):
for k in self._pkgindex_allowed_pkg_keys:
v = pkg_metadata.get(k)
- if v is not None:
+ if v:
d[k] = v
d["CPV"] = mycpv
@@ -1041,12 +1041,12 @@ class binarytree(object):
noiselevel=-1)
return
metadata = self._read_metadata(full_path, s)
- slot = metadata.get("SLOT")
+ invalid_depend = False
try:
self._eval_use_flags(cpv, metadata)
except portage.exception.InvalidDependString:
- slot = None
- if slot is None:
+ invalid_depend = True
+ if invalid_depend or not metadata.get("SLOT"):
writemsg(_("!!! Invalid binary package: '%s'\n") % full_path,
noiselevel=-1)
return
@@ -1126,6 +1126,21 @@ class binarytree(object):
return cpv
def _read_metadata(self, filename, st, keys=None):
+ """
+ Read metadata from a binary package. The returned metadata
+ dictionary will contain empty strings for any values that
+ are undefined (this is important because the _pkg_str class
+ distinguishes between missing and undefined values).
+
+ @param filename: File path of the binary package
+ @type filename: string
+ @param st: stat result for the binary package
+ @type st: os.stat_result
+ @param keys: optional list of specific metadata keys to retrieve
+ @type keys: iterable
+ @rtype: dict
+ @return: package metadata
+ """
if keys is None:
keys = self.dbapi._aux_cache_keys
metadata = self.dbapi._aux_cache_slot_dict()
@@ -1139,10 +1154,14 @@ class binarytree(object):
metadata[k] = _unicode(st.st_size)
else:
v = binary_metadata.get(_unicode_encode(k))
- if v is not None:
+ if v is None:
+ if k == "EAPI":
+ metadata[k] = "0"
+ else:
+ metadata[k] = ""
+ else:
v = _unicode_decode(v)
metadata[k] = " ".join(v.split())
- metadata.setdefault("EAPI", "0")
return metadata
def _inject_file(self, pkgindex, cpv, filename):
diff --git a/pym/portage/versions.py b/pym/portage/versions.py
index a028d93..adfb1c3 100644
--- a/pym/portage/versions.py
+++ b/pym/portage/versions.py
@@ -1,5 +1,5 @@
# versions.py -- core Portage functionality
-# Copyright 1998-2014 Gentoo Foundation
+# Copyright 1998-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from __future__ import unicode_literals
@@ -359,6 +359,12 @@ class _pkg_str(_unicode):
Instances are typically created in dbapi.cp_list() or the Atom contructor,
and propagate from there. Generally, code that pickles these objects will
manually convert them to a plain unicode object first.
+
+ Instances of this class will have missing attributes for metadata that
+ has not been passed into the constructor. The missing attributes are
+ used to distinguish missing metadata values from undefined metadata values.
+ For example, the repo attribute will be missing if the 'repository' key
+ is missing from the metadata dictionary.
"""
def __new__(cls, cpv, metadata=None, settings=None, eapi=None,
next reply other threads:[~2016-12-28 0:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-28 0:01 Zac Medico [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-05-17 18:40 [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/, pym/portage/ Zac Medico
2014-08-19 7:01 Michał Górny
2014-08-19 7:01 Michał Górny
2014-08-04 21:41 Arfrever Frehtes Taifersar Arahesis
2014-08-03 21:53 Pavel Kazakov
2011-10-16 21:13 Zac Medico
2011-09-06 18:35 Zac Medico
2011-05-05 15:13 Zac Medico
2011-03-27 20:57 Zac Medico
2011-02-14 4:02 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1482882551.67109fe41df07c9fa0e588b81f37ff61a71470f6.zmedico@gentoo \
--to=zmedico@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox