Skip to content

[bugfix] Write back lockfile after devbox update #1291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2023
Merged

Conversation

ipince
Copy link
Contributor

@ipince ipince commented Jul 20, 2023

Summary

After calling devbox update, we were not writing back to devbox.lock. ensurePkgsAreInstalled would then return early because the local lock file hadn't changed (since it re-reads devbox.lock from disk, rather than using the updated in-memory lockfile), so it would skip writing the lockfile as well.

This also makes the lockfile a bit more self-healing, since it will overwrite the current user's sysInfo entirely, rather than just adding the CAStorePath. This ensures that the StorePath and CAStorePath are written together.

How was it tested?

Manually, but plan to add testscripts in separate PR. I tested a few different scenarios, notably:

  1. devbox update adds system info for current user without changing system info for other systems.
  2. If current system info is missing something (either CAStorePath or Path), devbox update will restore it.
  3. If, say, CAStorePath is missing for the current system, and the user calls devbox shell, then we'll print a warning instructing the user to run devbox update. Calling it will then actually fix the lockfile and the warning will not be reprinted. It's worth mentioning that the warning will only be shown once to the user, because then they'll cache print-dev-env, so we won't re-exercise the path that computes CAStorePath. Not super ideal, but good enough I think.
  4. If current system info is missing entirely, it is added.
  5. If current system info exists and matches new one, nothing is done and we print "Already up-to-date"

@ipince ipince requested a review from mikeland73 July 20, 2023 23:18
@ipince ipince marked this pull request as ready for review July 20, 2023 23:18
Comment on lines 48 to 53
if i == nil {
return other == nil
}
if other == nil {
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i == nil || other == nil {
  return i == other
}
return *i == *other

@@ -54,6 +54,10 @@ func (d *Devbox) Update(ctx context.Context, pkgs ...string) error {
}
}

if err := d.lockfile.Save(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside to this approach is that if anything breaks while installing packages (which is fairly common due to stuff like insecure packages) then we leave the lockfile in a bad state that doesn't represent reality. This would have happened while updating nodejs@16

An alternative approach is to have local.IsUpToDate take a lock file instead of reading from disk. This would guarantee not running into this issue again. Similarly, localLock.Update() would take a lock file.

Not for this PR, but I think we could improve the local lock file API. Specifically I would make it private and just have the lock struct interact with it. e.g.

d.lockfile.LocalIsUpToDate()

And privatize local.Update (just have it be called by lock.Save() since they are both called together anyway.

This would make all the local stuff private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach is to have local.IsUpToDate take a lock file instead of reading from disk.

Yeah.. I have an implementation of this, but I prefer to get this in and later think about how to refactor the local lock stuff, since it may have larger implications.

@ipince ipince merged commit 617b0a4 into main Jul 21, 2023
@ipince ipince deleted the rodrigo/nixpkgs-update branch July 21, 2023 20:45
mikeland73 added a commit that referenced this pull request Jul 26, 2023
## Summary

Follow up to #1291.

This simplified the lockfile interface and mostly removes "local" lock
from public view.

It addresses this comment:
#1291 (comment)

## How was it tested?

`devbox update` on a package that needs system info downloaded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants