Skip to content

Commit

Permalink
Fix ordering for yum commands. (#153)
Browse files Browse the repository at this point in the history
disablerepo must come first or it'll override any enablerepo you might
have just set. Generally people want --disablerepo=* --enablerepo=REPO to just
process a specific repo and reversing makes that impossible.
  • Loading branch information
sfc-gh-jchacon authored Jul 22, 2022
1 parent cb98004 commit 7945eda
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions services/packages/server/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ type repoData struct {

// Optionally add the repo arg and then append the full package name to the list.
func addRepoAndPackage(out []string, p pb.PackageSystem, name string, version string, repos *repoData) []string {
if repos.enable != "" && p == pb.PackageSystem_PACKAGE_SYSTEM_YUM {
out = append(out, fmt.Sprintf("--enablerepo=%s", repos.enable))
}
// Disable must go first since it'll over enable otherwise and leave no repos potentially
if repos.disable != "" && p == pb.PackageSystem_PACKAGE_SYSTEM_YUM {
out = append(out, fmt.Sprintf("--disablerepo=%s", repos.disable))
}
if repos.enable != "" && p == pb.PackageSystem_PACKAGE_SYSTEM_YUM {
out = append(out, fmt.Sprintf("--enablerepo=%s", repos.enable))
}
// Tack the fully qualfied package name on. This assumes any vetting of args has already been done.
out = append(out, fmt.Sprintf("%s-%s", name, version))
return out
Expand Down
4 changes: 2 additions & 2 deletions services/packages/server/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestInstall(t *testing.T) {
// Test 2: A clean install. Validate we got expected output back.
// This is assuming yum based installs for testing command builder.
YumBin = "yum"
wantCmdLine := fmt.Sprintf("%s install-nevra -y --enablerepo=somerepo --disablerepo=otherrepo package-1.2.3", YumBin)
wantCmdLine := fmt.Sprintf("%s install-nevra -y --disablerepo=otherrepo --enablerepo=somerepo package-1.2.3", YumBin)

resp, err := client.Install(ctx, req)
testutil.FatalOnErr("clean install request", err, t)
Expand Down Expand Up @@ -385,7 +385,7 @@ func TestUpdate(t *testing.T) {
// This is assuming yum based installs for testing command builder.
YumBin = "yum"
wantValidateCmdLine := fmt.Sprintf("%s list installed package-0:1-1.2.3", YumBin)
wantCmdLine := fmt.Sprintf("%s update-to -y --enablerepo=somerepo --disablerepo=otherrepo package-0:1-4.5.6", YumBin)
wantCmdLine := fmt.Sprintf("%s update-to -y --disablerepo=otherrepo --enablerepo=somerepo package-0:1-4.5.6", YumBin)

resp, err := client.Update(ctx, req)
testutil.FatalOnErr("clean update request", err, t)
Expand Down

0 comments on commit 7945eda

Please sign in to comment.