Skip to content

[bin wrappers] Fixes: don't export PATH, and eval the symlink of the binary #1330

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 6 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/wrapnix/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,19 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error {
// 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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

change definition of this function to return sym link dir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd prefer not doing that, since I'd expect a function named CreateDevboxSymlink to return the path to the symlink, rather than its directory. Changing the name to CreateDevboxSymlinkAndGetDir feels verbose. I think its okay for the handling logic to do filepath.Dir

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but yeah, let me know if you feel strongly, and I can make the change.

// Get the symlink path; create the symlink directory if it doesn't exist.
curDir := xdg.CacheSubpath(filepath.Join("devbox", "bin", "current"))
if err := fileutil.EnsureDirExists(curDir, 0755, false /*chmod*/); err != nil {
return "", err
}
currentDevboxSymlinkPath := filepath.Join(curDir, "devbox")

devboxBinaryPath, err := os.Executable()
// Get the path to the devbox binary.
execPath, err := os.Executable()
if err != nil {
return "", errors.WithStack(err)
}
devboxBinaryPath, err := filepath.EvalSymlinks(execPath)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

let me harden this, so if an error is returned, then we do NOT error here. And then we skip modifying the PATH in the bin-wrappers.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think if this errors, you can simply delete the symlink and not recreate it. The rest can be the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

This will fail if existing symlink is already a loop. I think in that case we should just remove the symlink and not create a new one.

Copy link
Collaborator Author

@savil savil Jul 28, 2023

Choose a reason for hiding this comment

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

I didn't remove the symlink: i'm a little concerned that if it was previously created and was working fine, then by removing the symlink we may break some bin-wrappers (that are from a different project) that have the symlinkDir in their PATH

if err != nil {
return "", errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/wrapnix/wrapper.sh.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!{{ .BashPath }}

export PATH="{{ .DevboxSymlinkDir }}:$PATH"
PATH="{{ .DevboxSymlinkDir }}:$PATH"

{{/*
# If env variable has never been set by devbox we set it, but also
Expand Down