Skip to content

[Bug fix] Ensure bin-wrappers use latest devbox binary to prevent false update notifications #1324

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 3 commits into from
Jul 27, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Jul 27, 2023

Summary

Motivation

In #1260, the bin-wrappers were changed to invoke the devbox-binary, instead of the devbox-launcher. However, when devbox has been updated, these bin-wrappers have the older devbox-binary's path hardcoded. So, they call the older devbox-binary leading to two issues:

  1. runs older functionality of the older devbox binary
  2. re-prints the notice about "New devbox available. Run .... to update", despite the user already having updated their devbox.

Implementation

  1. Create a symlink that always points to the "current" devbox binary.
    • I use "current" instead of "latest" to be consistent with the Launcher's usage of these terms.
  2. In the bin-wrappers, we prepend the directory containing this devbox-symlink to PATH. The bin-wrappers revert back to directly invoking devbox, as in devbox shellenv.
    • This is done for robustness: if the symlink is missing, then the bin-wrappers do still invoke devbox via the launcher. This is problematic for users who have installed coreutils via devbox, but for most users this fallback would work.
  3. We ensure the bin-wrappers are created in ensurePackagesAreInstalled that runs in devbox.PrintEnv during devbox shellenv.
    • This is needed because we need existing users that have the bin-wrappers with the hardcoded DevboxExecutablePath to refresh their bin-wrappers. When they open a new terminal, devbox global shellenv would run, refreshing these bin-wrappers.
  4. Finally, we create the Devbox symlink during devbox version update, so that it points to the new Devbox binary.

Drawbacks
Switching between devbox versions (for testing and development) may lead to subtle unexpected behavior: The devbox-symlink will point to the version that created the bin-wrappers, rather than respecting the devbox of the PATH. We need to ensure we run devbox install or similar to re-create the bin-wrappers.

How was it tested?

  1. Sanity check to do devbox shell in examples/development/go/hello-world.
  2. Sanity check to do devbox run build using the devbox binary from this PR.
  3. Deleted devbox-symlink, and ran devbox version -v to ensure that it was re-created.

Copy link
Collaborator Author

savil commented Jul 27, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil force-pushed the savil/fix-bin-wrappers-accuracy branch from a4dff66 to c4433d6 Compare July 27, 2023 21:25
@savil savil requested review from mikeland73 and mohsenari July 27, 2023 21:27
@savil savil marked this pull request as ready for review July 27, 2023 21:27
@savil savil force-pushed the savil/fix-bin-wrappers-accuracy branch from c4433d6 to ff6e1ed Compare July 27, 2023 21:37
@savil savil force-pushed the savil/fix-bin-wrappers-accuracy branch from ff6e1ed to 2d3db2e Compare July 27, 2023 21:41
Copy link
Contributor

@mikeland73 mikeland73 left a comment

Choose a reason for hiding this comment

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

perfect 👍

// So, the bin-wrappers need to use a symlink to the latest devbox binary. This
// symlink is updated when devbox is updated.
func CreateDevboxSymlink() (string, error) {
curDir := xdg.CacheSubpath(filepath.Join("devbox", "current"))
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on making this devbox/bin/current instead? that way we keep it with all the other bins.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, I like that. Will update.

return "", errors.WithStack(err)
}

if err := os.Symlink(devboxBinaryPath, currentDevboxSymlinkPath); err != nil {
Copy link
Contributor

@mikeland73 mikeland73 Jul 27, 2023

Choose a reason for hiding this comment

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

Don't return error if error is os.ErrExist (to protect against race conditions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good call.

@savil
Copy link
Collaborator Author

savil commented Jul 27, 2023

I have a small commit locally to fix the code review feedback, but its not showing up on Github due to their incident:
https://www.githubstatus.com/incidents/xfmyxxhcknvj

@savil savil merged commit b24890b into main Jul 27, 2023
@savil savil deleted the savil/fix-bin-wrappers-accuracy branch July 27, 2023 23:33
savil added a commit that referenced this pull request Jul 28, 2023
…binary (#1330)

## Summary

This PR tries to address some concerns with #1324.

1. We drop `export` from `PATH` in the bin-wrappers. This would have
modified
PATH for all child programs, which we need not do. 

2. When creating the symlink, we ensure the target value is passed
through `EvalSymlink`.
Previously, it was set as the result of `os.Executable`, which may still
have been
a symlink.

## How was it tested?

did a basic sanity test of opening a devbox shell in a golang project
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