commit: 28d5b7e78e0fdad2479685ec257ab5b858195007 Author: Zac Medico <zmedico <AT> gentoo <DOT> org> AuthorDate: Sat May 16 20:57:11 2015 +0000 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org> CommitDate: Sat May 16 22:36:02 2015 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=28d5b7e7
egencache --update-pkg-desc-index: handle read-only repo (bug 549616) If the repo is read-only, write the cache to /var/cache/edb/dep where IndexedPortdb searches for it. X-Gentoo-Bug: 549616 X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=549616 Acked-by: Brian Dolbec <dolsen <AT> gentoo.org> bin/egencache | 17 ++++++++++++++++- pym/portage/repository/config.py | 12 ++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bin/egencache b/bin/egencache index f97432f..6075ccf 100755 --- a/bin/egencache +++ b/bin/egencache @@ -1086,8 +1086,23 @@ def egencache_main(args): ret.append(scheduler.returncode) if options.update_pkg_desc_index: + if repo_config.writable: + writable_location = repo_config.location + else: + writable_location = os.path.join(portdb.depcachedir, + repo_config.location.lstrip(os.sep)) + msg = [ + "WARNING: Repository is not writable: %s" % ( + repo_config.location,), + " Using cache directory instead: %s" % ( + writable_location,) + ] + msg = "".join(line + '\n' for line in msg) + writemsg_level(msg, + level=logging.WARNING, noiselevel=-1) + gen_index = GenPkgDescIndex(portdb, os.path.join( - repo_config.location, "metadata", "pkg_desc_index")) + writable_location, "metadata", "pkg_desc_index")) gen_index.run() ret.append(gen_index.returncode) diff --git a/pym/portage/repository/config.py b/pym/portage/repository/config.py index e44b619..05eedbe 100644 --- a/pym/portage/repository/config.py +++ b/pym/portage/repository/config.py @@ -26,6 +26,7 @@ from portage.env.loaders import KeyValuePairFileLoader from portage.util import (normalize_path, read_corresponding_eapi_file, shlex_split, stack_lists, writemsg, writemsg_level, _recursive_file_list) from portage.util._path import exists_raise_eaccess, isdir_raise_eaccess +from portage.util.path import first_existing from portage.localization import _ from portage import _unicode_decode from portage import _unicode_encode @@ -346,6 +347,17 @@ class RepoConfig(object): if new_repo.name is not None: self.missing_repo_name = new_repo.missing_repo_name + @property + def writable(self): + """ + Check if self.location is writable, or permissions are sufficient + to create it if it does not exist yet. + @rtype: bool + @return: True if self.location is writable or can be created, + False otherwise + """ + return os.access(first_existing(self.location), os.W_OK) + @staticmethod def _read_valid_repo_name(repo_path): name, missing = RepoConfig._read_repo_name(repo_path)
