Skip to content

Commit

Permalink
Refinements and fixes
Browse files Browse the repository at this point in the history
This change tweaks a few bits in the earlier changes to make things a
little nicer:

* clean up the flag help

* fixes the comments for LoadInvolvedPackages

* abort the allowed matcher loop early if we get a match

* re-works the allow/ignore code structure to reduce duplication
  • Loading branch information
kellyma2 committed Jan 3, 2025
1 parent 5ee08b5 commit 9168395
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewResolveCmd() *cobra.Command {
resolveCmd.Flags().BoolVarP(&resolveopts.nobest, "nobest", "n", false, "allow picking versions which are not the newest")
resolveCmd.Flags().StringArrayVarP(&resolveopts.repofiles, "repofile", "r", []string{"repo.yaml"}, "repository information file. Can be specified multiple times. Will be used by default if no explicit inputs are provided.")
resolveCmd.Flags().StringArrayVar(&resolveopts.forceIgnoreRegex, "force-ignore-with-dependencies", []string{}, "Packages matching these regex patterns will not be installed. Allows force-removing unwanted dependencies. Be careful, this can lead to hidden missing dependencies.")
resolveCmd.Flags().StringArrayVar(&resolveopts.onlyAllowRegex, "only-allow", []string{}, "Packages matching these regex patterns may be installed. Allows scoping dependencies. Be careful, this can lead to hidden missing dependencies.")
resolveCmd.Flags().StringArrayVar(&resolveopts.onlyAllowRegex, "only-allow", []string{}, "Packages matching these regex patterns may be installed. Allows limiting the dependency scope. Be careful, this can lead to hidden missing dependencies.")
// deprecated options
resolveCmd.Flags().StringVarP(&resolveopts.baseSystem, "fedora-base-system", "f", "fedora-release-container", "base system to use (e.g. fedora-release-server, centos-stream-release, ...)")
resolveCmd.Flags().MarkDeprecated("fedora-base-system", "use --basesystem instead")
Expand Down
35 changes: 20 additions & 15 deletions pkg/sat/sat.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func (r *Resolver) ticket() string {
return "x" + strconv.Itoa(r.varsCount)
}

// LoadInvolvedPackages takes a list of all involved packages to install, as well as a list of regular
// expressions which denote packages which should be taken into account for solving the problem, but they
// should then be ignored together with their requirements in the provided list of installed packages.
// Additionally, we can take a list of packages that the maximum selection desired.
// LoadInvolvedPackages takes a list of all involved packages to install, a list of regular expressions
// which denote packages which should be taken into account for solving the problem, but they should
// then be ignored together with their requirements in the provided list of installed packages, and also
// a list of regular expressions that may be used to limit the selection to matching packages.
func (r *Resolver) LoadInvolvedPackages(packages []*api.Package, ignoreRegex []string, allowRegex []string) error {
// Deduplicate and detect excludes
deduplicated := map[string]*api.Package{}
Expand All @@ -117,33 +117,38 @@ func (r *Resolver) LoadInvolvedPackages(packages []*api.Package, ignoreRegex []s
}
fullName := pkg.String()
if _, exists := deduplicated[fullName]; !exists {
matchedAllow := len(allowRegex) == 0

allowed := len(allowRegex) == 0
for _, rex := range allowRegex {
if match, err := regexp.MatchString(rex, fullName); err != nil {
return fmt.Errorf("failed to match package with regex '%v': %v", rex, err)
} else if match {
matchedAllow = true
allowed = true
break
}
}

if !matchedAllow {
packages[i].Format.Requires.Entries = nil
logrus.Warnf("Package %v does not match allow list", pkg.String())
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
} else {
ignored := len(ignoreRegex) == 0
if allowed {
for _, rex := range ignoreRegex {
if match, err := regexp.MatchString(rex, fullName); err != nil {
return fmt.Errorf("failed to match package with regex '%v': %v", rex, err)
} else if match {
packages[i].Format.Requires.Entries = nil
logrus.Warnf("Package %v is forcefully ignored by regex '%v'.", pkg.String(), rex)
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
ignored = true
break
}
}
}


if !allowed {
logrus.Warnf("Package %v is not explicitly allowed", pkg.String())
}

if !allowed || ignored {
packages[i].Format.Requires.Entries = nil
r.forceIgnoreWithDependencies[pkg.String()] = packages[i]
}

deduplicated[pkg.String()] = packages[i]
}
}
Expand Down

0 comments on commit 9168395

Please sign in to comment.