-
Notifications
You must be signed in to change notification settings - Fork 248
[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
Changes from 3 commits
0380f45
daf14e6
2a3f1f3
10af51c
2f91182
568eb78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,15 +55,19 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error { | |
if err != nil { | ||
return err | ||
} | ||
devboxSymlinkDir := "" | ||
if devboxSymlinkPath != "" { // may be empty if not possible to create symlink | ||
devboxSymlinkDir = filepath.Dir(devboxSymlinkPath) | ||
} | ||
|
||
for _, bin := range bins { | ||
if err = createWrapper(&createWrapperArgs{ | ||
devboxer: devbox, | ||
BashPath: bashPath, | ||
Command: bin, | ||
ShellEnvHash: shellEnvHash, | ||
DevboxSymlinkDir: filepath.Dir(devboxSymlinkPath), | ||
destPath: filepath.Join(destPath, filepath.Base(bin)), | ||
devboxer: devbox, | ||
BashPath: bashPath, | ||
Command: bin, | ||
ShellEnvHash: shellEnvHash, | ||
DevboxSymlinkDirIfExists: devboxSymlinkDir, | ||
destPath: filepath.Join(destPath, filepath.Base(bin)), | ||
}); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
@@ -72,7 +76,8 @@ func CreateWrappers(ctx context.Context, devbox devboxer) error { | |
return createSymlinksForSupportDirs(devbox.ProjectDir()) | ||
} | ||
|
||
// CreateDevboxSymlink creates a symlink to the devbox binary | ||
// CreateDevboxSymlink creates a symlink to the devbox binary. It may return an | ||
// empty string if it could not create the symlink. | ||
// | ||
// Needed because: | ||
// | ||
|
@@ -89,22 +94,33 @@ 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change definition of this function to return sym link dir. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, evalSymlinkErr := filepath.EvalSymlinks(execPath) | ||
// we check the error below, because we always want to remove the symlink | ||
|
||
// We will always re-create this symlink to ensure correctness. | ||
if err := os.Remove(currentDevboxSymlinkPath); err != nil && !errors.Is(err, os.ErrNotExist) { | ||
return "", errors.WithStack(err) | ||
} | ||
|
||
if evalSymlinkErr != nil { | ||
// This may return an error due to symlink loops. In that case, we | ||
// return an empty string, and the bin-wrapper should handle it accordingly. | ||
// nolint:nilerr | ||
return "", nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. return symlink dir |
||
} | ||
|
||
// Don't return error if error is os.ErrExist to protect against race conditions. | ||
if err := os.Symlink(devboxBinaryPath, currentDevboxSymlinkPath); err != nil && !errors.Is(err, os.ErrExist) { | ||
return "", errors.WithStack(err) | ||
|
@@ -115,11 +131,11 @@ func CreateDevboxSymlink() (string, error) { | |
|
||
type createWrapperArgs struct { | ||
devboxer | ||
BashPath string | ||
Command string | ||
ShellEnvHash string | ||
DevboxSymlinkDir string | ||
destPath string | ||
BashPath string | ||
Command string | ||
ShellEnvHash string | ||
DevboxSymlinkDirIfExists string | ||
destPath string | ||
} | ||
|
||
func createWrapper(args *createWrapperArgs) error { | ||
|
Uh oh!
There was an error while loading. Please reload this page.