Skip to content

Commit 1cc79b0

Browse files
authored
[update] Fix update bug (#1108)
## Summary Calling `removePackagesFromProfile` after forcing a resolve was causing an error because package doesn't exist in profile. Also, make update a little more forgiving, don't break if you can't remove pkg from profile. ## How was it tested? * Hand changed devbox.lock to older version of go and older hash. * deleted .devbox dir * Ran `devbox install` * Ran `devbox update` * Observed new version of go installed, old one removed. No error.
1 parent a7aed71 commit 1cc79b0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

internal/impl/update.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66

77
"go.jetpack.io/devbox/internal/lock"
8+
"go.jetpack.io/devbox/internal/searcher"
9+
"go.jetpack.io/devbox/internal/ux"
810
"go.jetpack.io/devbox/internal/wrapnix"
911
)
1012

@@ -27,20 +29,24 @@ func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
2729
continue
2830
}
2931
existing := d.lockfile.Packages[pkg]
30-
newEntry, err := d.lockfile.ForceResolve(pkg)
32+
newEntry, err := searcher.Client().Resolve(pkg)
3133
if err != nil {
3234
return err
3335
}
3436
if existing != nil && existing.Version != newEntry.Version {
3537
fmt.Fprintf(d.writer, "Updating %s %s -> %s\n", pkg, existing.Version, newEntry.Version)
3638
if err := d.removePackagesFromProfile(ctx, []string{pkg}); err != nil {
37-
return err
39+
// Warn but continue. TODO(landau): ensurePackagesAreInstalled should
40+
// sync the profile so we don't need to do this manually.
41+
ux.Fwarning(d.writer, "Failed to remove %s from profile: %s\n", pkg, err)
3842
}
3943
} else if existing == nil {
4044
fmt.Fprintf(d.writer, "Resolved %s to %[1]s %[2]s\n", pkg, newEntry.Resolved)
4145
} else {
4246
fmt.Fprintf(d.writer, "Already up-to-date %s %s\n", pkg, existing.Version)
4347
}
48+
// Set the new entry after we've removed the old package from the profile
49+
d.lockfile.Packages[pkg] = newEntry
4450
}
4551

4652
// TODO(landau): Improve output

0 commit comments

Comments
 (0)