From d2e466446c310f3acb28436c11afa6db2edef5d4 Mon Sep 17 00:00:00 2001 From: Tudor Marcu Date: Wed, 8 Aug 2018 17:57:18 -0700 Subject: [PATCH] Add excludepkgs option to repo command This features may help users guarantee correctness of bundles built by mixer in lieu of some shortcomings with dnf where dnf produces an unexpected dependency solution. This mainly happens when a user is intending to fully substitute a package from upstream's repo with one from their own. If anything is wrong with the substitution, a feature like this would expose the issue early on. Signed-off-by: Tudor Marcu --- builder/builder.go | 27 +++++++++++++++++++++++++++ mixer/cmd/repos.go | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/builder/builder.go b/builder/builder.go index 39ca36c..b628ba5 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -1839,6 +1839,33 @@ func (b *Builder) SetURLRepo(name, url string) error { return DNFConf.SaveTo(b.Config.Builder.DNFConf) } +// SetExcludesRepo sets the ecludes for the repo to [pkgs...] +func (b *Builder) SetExcludesRepo(reponame, pkgs string) error { + if err := b.NewDNFConfIfNeeded(); err != nil { + return err + } + + DNFConf, err := ini.Load(b.Config.Builder.DNFConf) + if err != nil { + return err + } + + s, err := DNFConf.GetSection(reponame) + if err != nil { + return err + } + + k, err := s.GetKey("excludepkgs") + if err != nil { + if k, err = DNFConf.Section(reponame).NewKey("excludepkgs", pkgs); err != nil { + return err + } + } + + k.SetValue(pkgs) + return DNFConf.SaveTo(b.Config.Builder.DNFConf) +} + // RemoveRepo removes a configured repo if it exists in the DNF configuration. // This will fail if a DNF conf has not yet been generated. func (b *Builder) RemoveRepo(name string) error { diff --git a/mixer/cmd/repos.go b/mixer/cmd/repos.go index 321759f..0e10478 100644 --- a/mixer/cmd/repos.go +++ b/mixer/cmd/repos.go @@ -16,6 +16,7 @@ package cmd import ( "fmt" + "strings" "github.com/clearlinux/mixer-tools/builder" @@ -66,12 +67,21 @@ var setURLRepoCmd = &cobra.Command{ Run: runSetURLRepo, } +var setExcludesRepoCmd = &cobra.Command{ + Use: "exclude [...]", + Short: "Exclude packages from a specified repo", + Long: `Exclude packages from a specified repo. These packages will be ignored during build bundles. Globbing is supported.`, + Args: cobra.MinimumNArgs(2), + Run: runExcludesRepo, +} + var repoCmds = []*cobra.Command{ addRepoCmd, removeRepoCmd, listReposCmd, initRepoCmd, setURLRepoCmd, + setExcludesRepoCmd, } func init() { @@ -83,6 +93,19 @@ func init() { RootCmd.AddCommand(repoCmd) } +func runExcludesRepo(cmd *cobra.Command, args []string) { + b, err := builder.NewFromConfig(configFile) + if err != nil { + fail(err) + } + + err = b.SetExcludesRepo(args[0], strings.Join(args[1:], " ")) + if err != nil { + fail(err) + } + fmt.Printf("Excluded packages from repo %s:\n%s\n", args[0], strings.Join(args[1:], "\n")) +} + func runAddRepo(cmd *cobra.Command, args []string) { b, err := builder.NewFromConfig(configFile) if err != nil {