Skip to content

Commit 76e1488

Browse files
authored
[update] Don't update if old last_modified, fix runx update (#1681)
## Summary This task is one of the follow ups from https://jetpack-io.slack.com/archives/C05KDNNN0Q6/p1702320680314359 If the package we get from nixhub is old, we should not try to update. Other fixes: * runx update was broken (or never implemented?) ## How was it tested? `devbox update` Simulated old package issue by changing lock file to a future date.
1 parent 9f2b788 commit 76e1488

File tree

5 files changed

+39
-28
lines changed

5 files changed

+39
-28
lines changed

devbox.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
"packages": {
33
"go": "latest",
44
"runx:golangci/golangci-lint": "latest",
5-
"runx:mvdan/gofumpt": "latest"
5+
"runx:mvdan/gofumpt": "latest",
66
},
77
"env": {
88
"GOENV": "off",
9-
"PATH": "$PATH:$PWD/dist"
9+
"PATH": "$PATH:$PWD/dist",
1010
},
1111
"shell": {
1212
"init_hook": [
13-
"test -z $FISH_VERSION && unset CGO_ENABLED GO111MODULE GOARCH GOFLAGS GOMOD GOOS GOROOT GOTOOLCHAIN GOWORK"
13+
"test -z $FISH_VERSION && unset CGO_ENABLED GO111MODULE GOARCH GOFLAGS GOMOD GOOS GOROOT GOTOOLCHAIN GOWORK",
1414
],
1515
"scripts": {
16-
"build": "go build -o dist/devbox ./cmd/devbox",
16+
"build": "go build -o dist/devbox ./cmd/devbox",
1717
"build-darwin-amd64": "GOOS=darwin GOARCH=amd64 go build -o dist/devbox-darwin-amd64 ./cmd/devbox",
1818
"build-darwin-arm64": "GOOS=darwin GOARCH=arm64 go build -o dist/devbox-darwin-arm64 ./cmd/devbox",
19-
"build-linux-amd64": "GOOS=linux GOARCH=amd64 go build -o dist/devbox-linux-amd64 ./cmd/devbox",
20-
"build-linux-arm64": "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox",
19+
"build-linux-amd64": "GOOS=linux GOARCH=amd64 go build -o dist/devbox-linux-amd64 ./cmd/devbox",
20+
"build-linux-arm64": "GOOS=linux GOARCH=arm64 go build -o dist/devbox-linux-arm64 ./cmd/devbox",
2121
"build-all": [
2222
"devbox run build-darwin-amd64",
2323
"devbox run build-darwin-arm64",
@@ -28,7 +28,7 @@
2828
"lint": "golangci-lint run --timeout 5m && scripts/gofumpt.sh",
2929
"fmt": "scripts/gofumpt.sh",
3030
"test": "go test -race -cover ./...",
31-
"update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go"
32-
}
33-
}
31+
"update-examples": "devbox run build && go run testscripts/testrunner/updater/main.go",
32+
},
33+
},
3434
}

devbox.lock

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,28 @@
22
"lockfile_version": "1",
33
"packages": {
44
"go@latest": {
5-
"last_modified": "2023-09-15T06:49:28Z",
6-
"resolved": "github:NixOS/nixpkgs/46688f8eb5cd6f1298d873d4d2b9cf245e09e88e#go_1_21",
5+
"last_modified": "2023-11-17T14:14:56Z",
6+
"resolved": "github:NixOS/nixpkgs/a71323f68d4377d12c04a5410e214495ec598d4c#go",
77
"source": "devbox-search",
8-
"version": "1.21.1",
8+
"version": "1.21.4",
99
"systems": {
1010
"aarch64-darwin": {
11-
"store_path": "/nix/store/jkhg33806wygpwpix47d2h5scfgn01i8-go-1.21.1"
11+
"store_path": "/nix/store/02cpvad60np366kmsqc3gnixbsw9jvg1-go-1.21.4"
1212
},
1313
"aarch64-linux": {
14-
"store_path": "/nix/store/sgkkfw6saficch0mviqyqyw6nj64kzf9-go-1.21.1"
14+
"store_path": "/nix/store/7y75b2ac80chlh6knld3943y46n3v9kf-go-1.21.4"
1515
},
1616
"x86_64-darwin": {
17-
"store_path": "/nix/store/w67nj5iqgnz0msi8i12kyh9nhsp2ci9n-go-1.21.1"
17+
"store_path": "/nix/store/0djljz0g4s6f55xcnw7fpzcy7af7rxid-go-1.21.4"
1818
},
1919
"x86_64-linux": {
20-
"store_path": "/nix/store/jk0bqfsjijia52vks1wxqnn4s6dxaiqp-go-1.21.1"
20+
"store_path": "/nix/store/y7abhs9glxfcg7lgcdc8i4ml5wg5ly92-go-1.21.4"
2121
}
2222
}
2323
},
2424
"runx:golangci/golangci-lint@latest": {
25-
"resolved": "golangci/golangci-lint@v1.54.2",
26-
"version": "v1.54.2"
25+
"resolved": "golangci/golangci-lint@v1.55.2",
26+
"version": "v1.55.2"
2727
},
2828
"runx:mvdan/gofumpt@latest": {
2929
"resolved": "mvdan/[email protected]",

internal/impl/update.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ func (d *Devbox) mergeResolvedPackageToLockfile(
114114
}
115115

116116
if existing.Version != resolved.Version {
117+
if existing.LastModified > resolved.LastModified {
118+
ux.Fwarning(
119+
d.stderr,
120+
"Resolved version for %s has older last_modified time. Not updating\n",
121+
pkg,
122+
)
123+
return nil
124+
}
117125
ux.Finfo(d.stderr, "Updating %s %s -> %s\n", pkg, existing.Version, resolved.Version)
118126
useResolvedPackageInLockfile(lockfile, pkg, resolved, existing)
119127
return nil

internal/lock/lockfile.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,7 @@ func (f *File) Resolve(pkg string) (*Package, error) {
7373
if !hasEntry || entry.Resolved == "" {
7474
locked := &Package{}
7575
var err error
76-
if pkgtype.IsRunX(pkg) {
77-
ref, err := ResolveRunXPackage(context.TODO(), pkg)
78-
if err != nil {
79-
return nil, err
80-
}
81-
locked = &Package{
82-
Resolved: ref.String(),
83-
Version: ref.Version,
84-
}
85-
} else if _, _, versioned := searcher.ParseVersionedPackage(pkg); versioned {
76+
if _, _, versioned := searcher.ParseVersionedPackage(pkg); pkgtype.IsRunX(pkg) || versioned {
8677
locked, err = f.FetchResolvedPackage(pkg)
8778
if err != nil {
8879
return nil, err

internal/lock/resolve.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"go.jetpack.io/devbox/internal/boxcli/featureflag"
1515
"go.jetpack.io/devbox/internal/boxcli/usererr"
1616
"go.jetpack.io/devbox/internal/debug"
17+
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
1718
"go.jetpack.io/devbox/internal/nix"
1819
"go.jetpack.io/devbox/internal/searcher"
1920
"golang.org/x/sync/errgroup"
@@ -31,6 +32,17 @@ func (f *File) FetchResolvedPackage(pkg string) (*Package, error) {
3132
return nil, usererr.New("No version specified for %q.", name)
3233
}
3334

35+
if pkgtype.IsRunX(pkg) {
36+
ref, err := ResolveRunXPackage(context.TODO(), pkg)
37+
if err != nil {
38+
return nil, err
39+
}
40+
return &Package{
41+
Resolved: ref.String(),
42+
Version: ref.Version,
43+
}, nil
44+
}
45+
3446
packageVersion, err := searcher.Client().Resolve(name, version)
3547
if err != nil {
3648
return nil, errors.Wrapf(nix.ErrPackageNotFound, "%s@%s", name, version)

0 commit comments

Comments
 (0)