Skip to content

Commit

Permalink
Fix package name handling to retain version and strip ‘@’ suffix
Browse files Browse the repository at this point in the history
Signed-off-by: Emin Aktas <[email protected]>
  • Loading branch information
eminaktas committed Jan 9, 2025
1 parent 995ee5a commit 3a16d80
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/build/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,10 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
// special characters that delimit the package name from the cosntraint
// so lop off the package name and stick the rest of the constraint into
// the versions map.
if idx := strings.IndexAny(orig, "=<>~"); idx >= 0 {
if idx := strings.IndexAny(orig, "@=<>~"); idx >= 0 {
name = orig[:idx]
}

originalPackages.packages.Insert(name)
originalPackages.versions[name] = strings.TrimPrefix(orig, name)
}
Expand Down Expand Up @@ -235,7 +236,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
// Append all of the resolved and unified packages with an exact match
// based on the resolved version we found.
for _, pkg := range sets.List(acc.packages) {
pl = append(pl, fmt.Sprintf("%s=%s", pkg, acc.versions[pkg]))
pkgName := fmt.Sprintf("%s=%s", pkg, acc.versions[pkg])
// Add back the version if that is stripped before
if originalPackages.versions[pkg] != "" {
pkgName = pkgName + originalPackages.versions[pkg]
}
pl = append(pl, pkgName)
}
// Sort the package list explicitly with the `=` included.
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)
Expand All @@ -249,7 +255,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
for _, input := range inputs {
pl := make([]string, 0, len(input.packages))
for _, pkg := range sets.List(input.packages) {
pl = append(pl, fmt.Sprintf("%s=%s", pkg, input.versions[pkg]))
pkgName := fmt.Sprintf("%s=%s", pkg, input.versions[pkg])
// Add back the version if that is stripped before
if originalPackages.versions[pkg] != "" {
pkgName = pkgName + originalPackages.versions[pkg]
}
pl = append(pl, pkgName)
}
// Sort the package list explicitly with the `=` included.
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)
Expand Down

0 comments on commit 3a16d80

Please sign in to comment.