Skip to content

Commit 3a16d80

Browse files
committed
Fix package name handling to retain version and strip ‘@’ suffix
Signed-off-by: Emin Aktas <[email protected]>
1 parent 995ee5a commit 3a16d80

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/build/lock.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
134134
// special characters that delimit the package name from the cosntraint
135135
// so lop off the package name and stick the rest of the constraint into
136136
// the versions map.
137-
if idx := strings.IndexAny(orig, "=<>~"); idx >= 0 {
137+
if idx := strings.IndexAny(orig, "@=<>~"); idx >= 0 {
138138
name = orig[:idx]
139139
}
140+
140141
originalPackages.packages.Insert(name)
141142
originalPackages.versions[name] = strings.TrimPrefix(orig, name)
142143
}
@@ -235,7 +236,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
235236
// Append all of the resolved and unified packages with an exact match
236237
// based on the resolved version we found.
237238
for _, pkg := range sets.List(acc.packages) {
238-
pl = append(pl, fmt.Sprintf("%s=%s", pkg, acc.versions[pkg]))
239+
pkgName := fmt.Sprintf("%s=%s", pkg, acc.versions[pkg])
240+
// Add back the version if that is stripped before
241+
if originalPackages.versions[pkg] != "" {
242+
pkgName = pkgName + originalPackages.versions[pkg]
243+
}
244+
pl = append(pl, pkgName)
239245
}
240246
// Sort the package list explicitly with the `=` included.
241247
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)
@@ -249,7 +255,12 @@ func unify(originals []string, inputs []resolved) (map[string][]string, map[stri
249255
for _, input := range inputs {
250256
pl := make([]string, 0, len(input.packages))
251257
for _, pkg := range sets.List(input.packages) {
252-
pl = append(pl, fmt.Sprintf("%s=%s", pkg, input.versions[pkg]))
258+
pkgName := fmt.Sprintf("%s=%s", pkg, input.versions[pkg])
259+
// Add back the version if that is stripped before
260+
if originalPackages.versions[pkg] != "" {
261+
pkgName = pkgName + originalPackages.versions[pkg]
262+
}
263+
pl = append(pl, pkgName)
253264
}
254265
// Sort the package list explicitly with the `=` included.
255266
// This is because (foo, foo-bar) sorts differently than (foo=1, foo-bar=1)

0 commit comments

Comments
 (0)