Skip to content

Commit 63a15ed

Browse files
committed
update all fields of package, when updating system-infos
1 parent 63a3de8 commit 63a15ed

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

devbox.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"lockfile_version": "1",
33
"packages": {
44
"go@latest": {
5-
"last_modified": "2023-09-10T10:53:27Z",
5+
"last_modified": "2023-09-15T06:49:28Z",
66
"resolved": "github:NixOS/nixpkgs/46688f8eb5cd6f1298d873d4d2b9cf245e09e88e#go_1_21",
77
"source": "devbox-search",
88
"version": "1.21.1",

internal/impl/update.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,7 @@ func (d *Devbox) mergeResolvedPackageToLockfile(
121121
// sync the profile so we don't need to do this manually.
122122
ux.Fwarning(d.stderr, "Failed to remove %s from profile: %s\n", pkg, err)
123123
}
124-
resolved.AllowInsecure = existing.AllowInsecure
125-
lockfile.Packages[pkg.Raw] = resolved
124+
useResolved(lockfile, pkg, resolved, existing)
126125
return nil
127126
}
128127

@@ -133,30 +132,33 @@ func (d *Devbox) mergeResolvedPackageToLockfile(
133132
lockfile.Packages[pkg.Raw].Systems = map[string]*lock.SystemInfo{}
134133
}
135134

135+
newSystems := map[string]*lock.SystemInfo{}
136136
userSystem := nix.System()
137137
updated := false
138138
for sysName, newSysInfo := range resolved.Systems {
139+
newSystems[sysName] = newSysInfo
140+
141+
// Check whether we are actually updating any system info.
139142
if sysName == userSystem {
140143
// The resolved pkg has a system info for the user's system, so add/overwrite it.
141144
if !newSysInfo.Equals(existing.Systems[userSystem]) {
142145
// We only guard this so that the ux messaging is accurate. We could overwrite every time.
143-
lockfile.Packages[pkg.Raw].Systems[userSystem] = newSysInfo
144146
updated = true
145147
}
146148
} else {
147149
// Add other system infos if they don't exist, or if we have a different StorePath. This may
148-
// overwrite an existing CAPath, but to ensure correctness we should ensure that all StorePaths
150+
// overwrite an existing StorePath, but to ensure correctness we should ensure that all StorePaths
149151
// come from the same package version.
150152
existingSysInfo, exists := existing.Systems[sysName]
151153
if !exists || existingSysInfo.StorePath != newSysInfo.StorePath {
152-
lockfile.Packages[pkg.Raw].Systems[sysName] = newSysInfo
153154
updated = true
154155
}
155156
}
156157
}
157158
if updated {
158-
// if we are updating the system info, then we should also update the resolved path
159-
lockfile.Packages[pkg.Raw].Resolved = resolved.Resolved
159+
// if we are updating the system info, then we should also update the other fields
160+
useResolved(lockfile, pkg, resolved, existing)
161+
lockfile.Packages[pkg.Raw].Systems = newSystems
160162

161163
ux.Finfo(d.stderr, "Updated system information for %s\n", pkg)
162164
return nil
@@ -193,3 +195,13 @@ func (d *Devbox) attemptToUpgradeFlake(pkg *devpkg.Package) error {
193195

194196
return nil
195197
}
198+
199+
func useResolved(
200+
lockfile *lock.File,
201+
pkg *devpkg.Package,
202+
resolved *lock.Package,
203+
existing *lock.Package,
204+
) {
205+
lockfile.Packages[pkg.Raw] = resolved
206+
lockfile.Packages[pkg.Raw].AllowInsecure = existing.AllowInsecure
207+
}

0 commit comments

Comments
 (0)