From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BC918139694 for ; Sat, 25 Feb 2017 01:24:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9E3BDE0CCC; Sat, 25 Feb 2017 01:24:00 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 68986E0CCC for ; Sat, 25 Feb 2017 01:24:00 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 09209340BEA for ; Sat, 25 Feb 2017 01:23:59 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id E5FEF538D for ; Sat, 25 Feb 2017 01:23:56 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1487985224.79103f99799c9365389290e812213c46e006c019.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/emaint/modules/sync/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/emaint/modules/sync/sync.py X-VCS-Directories: pym/portage/emaint/modules/sync/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 79103f99799c9365389290e812213c46e006c019 X-VCS-Branch: master Date: Sat, 25 Feb 2017 01:23:56 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 08296e70-ab9a-4455-892c-f6a5dc0a3c48 X-Archives-Hash: 3625975af5c48a3866a247bf01dafc23 commit: 79103f99799c9365389290e812213c46e006c019 Author: Alexandru Elisei gmail com> AuthorDate: Tue Feb 21 12:02:38 2017 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Feb 25 01:13:44 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=79103f99 sync.py: validate repos in _get_repos() (bug 567478, 576282, 601054) SyncRepos._get_repos() now receives an optional match argument, which represents the names of the repositories to retrieve. SyncRepos._get_repos() will return a tuple of (result, repos, messages). Result is True on success and False on failure, repos is a list of repository objects and messages is a list of errors or warnings generated while getting the repos. Repos given to emerge --sync are no longer treated separately. After commit 75f0936 multiple repos can be given to SyncRepos.repo() via emerge --sync. SyncRepos._get_repos() will fail if at least one of these repos cannot be synced (the repo is missing or has sync disabled). If no repos are specified, SyncRepos._get_repos() ignores repos with sync-type empty as per the portage.5 man file. If repos are specified, the function will fail. This check was previously done in _sync(), which could lead to a situation when a repo given to emerge --sync or emaint sync --repo was not synced and the operation was considered successful. SyncRepos._get_repos() also validates repos by checking for a non-empty sync-uri. Finding a repo with an empty sync-uri is considered a failure and the appropriate message will be generated. pym/portage/emaint/modules/sync/sync.py | 120 +++++++++++++++----------------- 1 file changed, 58 insertions(+), 62 deletions(-) diff --git a/pym/portage/emaint/modules/sync/sync.py b/pym/portage/emaint/modules/sync/sync.py index 08a92a7a8..9e3ca069e 100644 --- a/pym/portage/emaint/modules/sync/sync.py +++ b/pym/portage/emaint/modules/sync/sync.py @@ -89,47 +89,50 @@ class SyncRepos(object): def auto_sync(self, **kwargs): '''Sync auto-sync enabled repos''' options = kwargs.get('options', None) - selected = self._get_repos(True) if options: return_messages = options.get('return-messages', False) else: return_messages = False - return self._sync(selected, return_messages, - emaint_opts=options) + success, repos, msgs = self._get_repos(auto_sync_only=True) + if not success: + if return_messages: + return (False, msgs) + return (False, None) + return self._sync(repos, return_messages, emaint_opts=options) def all_repos(self, **kwargs): '''Sync all repos defined in repos.conf''' - selected = self._get_repos(auto_sync_only=False) options = kwargs.get('options', None) if options: return_messages = options.get('return-messages', False) else: return_messages = False - return self._sync(selected, return_messages, - emaint_opts=options) + success, repos, msgs = self._get_repos(auto_sync_only=False) + if not success: + if return_messages: + return (False, msgs) + return (False, None) + return self._sync(repos, return_messages, emaint_opts=options) def repo(self, **kwargs): '''Sync the specified repo''' options = kwargs.get('options', None) if options: - repos = options.get('repo', '') + repo_names = options.get('repo', '') return_messages = options.get('return-messages', False) else: return_messages = False - if isinstance(repos, _basestring): - repos = repos.split() - available = self._get_repos(auto_sync_only=False) - selected = self._match_repos(repos, available) - if not selected: - msgs = [red(" * ") + "The specified repos were not found: %s" % - (bold(", ".join(repos))) + "\n ...returning"] + if isinstance(repo_names, _basestring): + repo_names = repo_names.split() + success, repos, msgs = self._get_repos(auto_sync_only=False, + match_repos=repo_names) + if not success: if return_messages: return (False, msgs) return (False, None) - return self._sync(selected, return_messages, - emaint_opts=options) + return self._sync(repos, return_messages, emaint_opts=options) @staticmethod @@ -147,44 +150,40 @@ class SyncRepos(object): return selected - def _get_repos(self, auto_sync_only=True): - selected_repos = [] - unknown_repo_names = [] - missing_sync_type = [] - if self.emerge_config.args: - for repo_name in self.emerge_config.args: - #print("_get_repos(): repo_name =", repo_name) - try: - repo = self.emerge_config.target_config.settings.repositories[repo_name] - except KeyError: - unknown_repo_names.append(repo_name) - else: - selected_repos.append(repo) - if repo.sync_type is None: - missing_sync_type.append(repo) - - if unknown_repo_names: - writemsg_level("!!! %s\n" % _("Unknown repo(s): %s") % - " ".join(unknown_repo_names), - level=logging.ERROR, noiselevel=-1) - - if missing_sync_type: - writemsg_level("!!! %s\n" % - _("Missing sync-type for repo(s): %s") % - " ".join(repo.name for repo in missing_sync_type), - level=logging.ERROR, noiselevel=-1) - - if unknown_repo_names or missing_sync_type: - writemsg_level("Missing or unknown repos... returning", - level=logging.INFO, noiselevel=2) - return [] + def _get_repos(self, auto_sync_only=True, match_repos=None): + msgs = [] + repos = self.emerge_config.target_config.settings.repositories + if match_repos is not None: + repos = self._match_repos(match_repos, repos) + if len(repos) < len(match_repos): + available = [repo.name for repo in repos] + missing = [repo for repo in match_repos if repo not in available] + msgs.append(red(" * ") + "The specified repo(s) were not found: %s" % + (" ".join(repo for repo in missing)) + \ + "\n ...returning") + return (False, repos, msgs) - else: - selected_repos.extend(self.emerge_config.target_config.settings.repositories) - #print("_get_repos(), selected =", selected_repos) if auto_sync_only: - return self._filter_auto(selected_repos) - return selected_repos + repos = self._filter_auto(repos) + + sync_disabled = [repo for repo in repos if repo.sync_type is None] + if sync_disabled: + repos = [repo for repo in repos if repo.sync_type is not None] + if match_repos is not None: + msgs.append(red(" * " ) + "The specified repo(s) have sync disabled: %s" % + " ".join(repo.name for repo in sync_disabled) + \ + "\n ...returning") + return (False, repos, msgs) + + missing_sync_uri = [repo for repo in repos if repo.sync_uri is None] + if missing_sync_uri: + repos = [repo for repo in repos if repo.sync_uri is not None] + msgs.append(red(" * ") + "The specified repo(s) are missing sync-uri: %s" % + " ".join(repo.name for repo in missing_sync_uri) + \ + "\n ...returning") + return (False, repos, msgs) + + return (True, repos, msgs) def _filter_auto(self, repos): @@ -195,8 +194,13 @@ class SyncRepos(object): return selected - def _sync(self, selected_repos, return_messages, - emaint_opts=None): + def _sync(self, selected_repos, return_messages, emaint_opts=None): + msgs = [] + if not selected_repos: + if return_messages: + msgs.append("Nothing to sync... returning") + return (True, msgs) + return (True, None) if emaint_opts is not None: for k, v in emaint_opts.items(): @@ -204,14 +208,6 @@ class SyncRepos(object): k = "--" + k.replace("_", "-") self.emerge_config.opts[k] = v - selected_repos = [repo for repo in selected_repos if repo.sync_type is not None] - msgs = [] - if not selected_repos: - msgs.append("Nothing to sync... returning") - if return_messages: - msgs.extend(self.rmessage([('None', os.EX_OK)], 'sync')) - return (True, msgs) - return (True, None) # Portage needs to ensure a sane umask for the files it creates. os.umask(0o22)