From 9c07411cfe8a18bec328f156ce71dc484dc91570 Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 14 Nov 2022 11:15:43 +0100 Subject: [PATCH] Fix interactive install to honor no-*gpgcheck from commandline When originally implementing the per-source gpgcheck flags in answerfile[1], the full code was moved to an anwerfile-only location, breaking the original interactive-install implementation (and then following code review[2] the working code for interactive install disappeared further from the patch series). This moves the Repository flag-setting to `add_repos()` common code, while leaving the flag computation to the caller, since only the answerfile case has to do any non-trivial logic. - [1] https://github.com/xcp-ng/host-installer/commit/06b700789f2c22d1c78285f9583937511e4d3c07 - [2] https://github.com/xcp-ng/host-installer/pull/2#discussion_r1012080594 Signed-off-by: Yann Dirson --- backend.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/backend.py b/backend.py index d5a2e39a..6ffe79bb 100644 --- a/backend.py +++ b/backend.py @@ -373,7 +373,7 @@ def handleRepos(repos, ans): main_repositories = [] update_repositories = [] - def add_repos(main_repositories, update_repositories, repos): + def add_repos(main_repositories, update_repositories, repos, repo_gpgcheck, gpgcheck): """Add repositories to the appropriate list, ensuring no duplicates, that the main repository is at the beginning, and that the order of the rest is maintained.""" @@ -390,28 +390,28 @@ def add_repos(main_repositories, update_repositories, repos): else: repo_list.append(repo) + if repo_list is main_repositories: # i.e., if repo is a "main repository" + repo.setRepoGpgCheck(repo_gpgcheck) + repo.setGpgCheck(gpgcheck) + + default_repo_gpgcheck = answers.get('repo-gpgcheck', True) + default_gpgcheck = answers.get('gpgcheck', True) # A list of sources coming from the answerfile if 'sources' in answers_pristine: for i in answers_pristine['sources']: repos = repository.repositoriesFromDefinition(i['media'], i['address']) - add_repos(main_repositories, update_repositories, repos) - repo_gpgcheck = (answers.get('repo-gpgcheck', True) if i['repo_gpgcheck'] is None - else i['repo_gpgcheck']) - gpgcheck = (answers.get('gpgcheck', True) if i['gpgcheck'] is None - else i['gpgcheck']) - for repo in repos: - if repo in main_repositories: - repo.setRepoGpgCheck(repo_gpgcheck) - repo.setGpgCheck(gpgcheck) + repo_gpgcheck = default_repo_gpgcheck if i['repo_gpgcheck'] is None else i['repo_gpgcheck'] + gpgcheck = default_gpgcheck if i['gpgcheck'] is None else i['gpgcheck'] + add_repos(main_repositories, update_repositories, repos, repo_gpgcheck, gpgcheck) # A single source coming from an interactive install if 'source-media' in answers_pristine and 'source-address' in answers_pristine: repos = repository.repositoriesFromDefinition(answers_pristine['source-media'], answers_pristine['source-address']) - add_repos(main_repositories, update_repositories, repos) + add_repos(main_repositories, update_repositories, repos, default_repo_gpgcheck, default_gpgcheck) for media, address in answers_pristine['extra-repos']: repos = repository.repositoriesFromDefinition(media, address) - add_repos(main_repositories, update_repositories, repos) + add_repos(main_repositories, update_repositories, repos, default_repo_gpgcheck, default_gpgcheck) if not main_repositories or main_repositories[0].identifier() != MAIN_REPOSITORY_NAME: raise RuntimeError("No main repository found")