From 90f7981b69ac550f51398440c1341c65089aa331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miquel=20Sabat=C3=A9=20Sol=C3=A0?= Date: Fri, 25 Oct 2024 16:24:12 +0200 Subject: [PATCH] Honor auto-import-gpg-keys flag on migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parsing of CLI arguments and how these are passed through the internal SCC client, zypper and other tools is not ideal and needs to be re-worked quite urgently. This is why other silly bugs have appeared in which we are not passing the correct arguments to our backend code. Until this rework is not done, let's simply apply this quick fix which simply passes the `--gpg-auto-import-keys` flag to the zypper backend when finding product packages. Fixes bsc#1231328 Signed-off-by: Miquel Sabaté Solà --- cmd/zypper-migration/migration.go | 10 +++++----- internal/zypper/zypper.go | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/zypper-migration/migration.go b/cmd/zypper-migration/migration.go index d70d4659..5f77bd6e 100644 --- a/cmd/zypper-migration/migration.go +++ b/cmd/zypper-migration/migration.go @@ -497,8 +497,8 @@ func compareEditions(left, right string) int { return 0 } -func cleanupProductRepos(p connect.Product, force bool) error { - productPackages, err := zypper.FindProductPackages(p.Name) +func cleanupProductRepos(p connect.Product, force, autoImportRepoKeys bool) error { + productPackages, err := zypper.FindProductPackages(p.Name, autoImportRepoKeys) if err != nil { return err } @@ -564,7 +564,7 @@ func isSUSEService(service zypper.ZypperService) bool { // adds/removes services to match target state // disables obsolete repos // returns base product version string -func migrateSystem(migration connect.MigrationPath, forceDisableRepos bool) (string, error) { +func migrateSystem(migration connect.MigrationPath, forceDisableRepos, autoImportRepoKeys bool) (string, error) { var baseProductVersion string systemServices, _ := zypper.InstalledServices() @@ -587,7 +587,7 @@ func migrateSystem(migration connect.MigrationPath, forceDisableRepos bool) (str } } - if err := cleanupProductRepos(p, forceDisableRepos); err != nil { + if err := cleanupProductRepos(p, forceDisableRepos, autoImportRepoKeys); err != nil { return baseProductVersion, err } @@ -678,7 +678,7 @@ func applyMigration(migration connect.MigrationPath, systemProducts []connect.Pr } } - baseProductVersion, err := migrateSystem(migration, nonInteractive || forceDisableRepos) + baseProductVersion, err := migrateSystem(migration, nonInteractive || forceDisableRepos, autoImportRepoKeys) if err != nil { return fsInconsistent, err } diff --git a/internal/zypper/zypper.go b/internal/zypper/zypper.go index c7cea3d5..e5ea6589 100644 --- a/internal/zypper/zypper.go +++ b/internal/zypper/zypper.go @@ -358,9 +358,13 @@ func parseSearchResultXML(xmlDoc []byte) ([]Package, error) { } // FindProductPackages returns list of product packages for given product -func FindProductPackages(identifier string) ([]Package, error) { +func FindProductPackages(identifier string, autoImportRepoKeys bool) ([]Package, error) { args := []string{"--xmlout", "--no-refresh", "--non-interactive", "search", "-s", "--match-exact", "-t", "product", identifier} + if autoImportRepoKeys { + args = append([]string{"--gpg-auto-import-keys"}, args...) + } + // Don't fail when zypper exits with 104 (no product found) or 6 (no repositories) output, err := zypperRun(args, []int{zypperOK, zypperErrNoRepos, zypperInfoCapNotFound}) if err != nil {