commit: 976c1133100f6da81cd8d6e13f8a723a9fc7cd85 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Sun Jun 7 02:25:11 2020 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sun Jun 7 02:53:27 2020 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=976c1133
_better_cache._scan_cat: avoid stat calls (bug 725934) When processing category listdir results, do not use os.path.isdir to identify packages, in order to avoid unecessary stat calls. Instead, use the Atom class to validate package names. This may cause creation of some cache entries for non-packages, but it will not do any harm since these entries will never be accessed via the __getitem__ method. Bug: https://bugs.gentoo.org/725934 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org> lib/portage/dbapi/porttree.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/portage/dbapi/porttree.py b/lib/portage/dbapi/porttree.py index 08af17bcd..ed992d1e2 100644 --- a/lib/portage/dbapi/porttree.py +++ b/lib/portage/dbapi/porttree.py @@ -164,8 +164,13 @@ class _better_cache(object): raise continue for p in pkg_list: - if os.path.isdir(cat_dir + "/" + p): - self._items[cat + "/" + p].append(repo) + try: + atom = Atom("%s/%s" % (cat, p)) + except InvalidAtom: + continue + if atom != atom.cp: + continue + self._items[atom.cp].append(repo) self._scanned_cats.add(cat)
