Skip to content

Commit

Permalink
Merge pull request #3 from chainguard-dev/add_support_for_multiple_ve…
Browse files Browse the repository at this point in the history
…rsions

support specifying the version with the package name
  • Loading branch information
hectorj2f authored Nov 21, 2024
2 parents d51d668 + 88166c6 commit e5d94c8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package pkg

import (
"fmt"
"log"

"github.com/chainguard-dev/cargobump/pkg/run"
"github.com/chainguard-dev/cargobump/pkg/types"
"golang.org/x/mod/semver"
"log"
)

func Update(patches map[string]*types.Package, pkgs []types.CargoPackage, cargoRoot string) error {
Expand All @@ -22,6 +21,19 @@ func Update(patches map[string]*types.Package, pkgs []types.CargoPackage, cargoR
}
log.Printf("Package updated successfully: %s to version %s\n", p.Name, v.Version)
}
// Try updating packages referring to a specific version
packageVersion := p.Name + "@" + p.Version
v, existsVersionRef := patches[packageVersion]
if existsVersionRef {
log.Printf("Update package with a specific version: %s\n", packageVersion)
if semver.Compare(p.Version, patches[packageVersion].Version) > 0 {
return fmt.Errorf("warning: package %s with version '%s' is already at version %s", packageVersion, v.Version, p.Version)
}
if output, err := run.CargoUpdatePackage(packageVersion, v.Version, cargoRoot); err != nil {
return fmt.Errorf("failed to run cargo update '%v' with error: '%v'", output, err)
}
log.Printf("Package updated successfully: %s to version %s\n", packageVersion, v.Version)
}
}
return nil
}

0 comments on commit e5d94c8

Please sign in to comment.