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

Conversation

savil
Copy link
Collaborator

@savil savil commented Jul 28, 2023

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

Copy link
Collaborator Author

savil commented Jul 28, 2023

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@savil savil requested review from mikeland73 and gcurtis and removed request for mikeland73 July 28, 2023 18:25
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.

@savil savil marked this pull request as draft July 28, 2023 18:27
if err != nil {
return "", errors.WithStack(err)
}
devboxBinaryPath, err := filepath.EvalSymlinks(execPath)
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

@savil savil requested a review from mikeland73 July 28, 2023 18:53
@savil savil marked this pull request as ready for review July 28, 2023 18:53
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.

I think we should always add the symlink dir to path even if the sym link was not created. The reason is that those binwrappers will work correctly when we are able to create the sym link.

Note that adding an empty dir to PATH does no harm.

Otherwise, we end up with a bunch of bin wrappers that need to be recreated later.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

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

return symlink dir

@@ -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) {
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.

@savil
Copy link
Collaborator Author

savil commented Jul 28, 2023

I think we should always add the symlink dir to path even if the sym link was not created. The reason is that those binwrappers will work correctly when we are able to create the sym link.

hm fair point

@savil savil requested a review from mikeland73 July 28, 2023 19:23
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.

OK, promise last comments.

Change CreateDevboxSymlink to return error only. Rename it to CreateDevboxSymlinkIfPossible. it returns nil if evalSymlinkErr != nil

create package variable
var devboxSymlinkDir = xdg.CacheSubpath(filepath.Join("devbox", "bin", "current"))

use that variable in CreateDevboxSymlinkIfPossible and also in CreateWrappers

@savil
Copy link
Collaborator Author

savil commented Jul 28, 2023

@mikeland73 cool, PTAL

@savil savil requested a review from mikeland73 July 28, 2023 19:54
@savil savil merged commit 31d2c00 into main Jul 28, 2023
@savil savil deleted the savil/fix-bin-wrappers-accuracy-2 branch July 28, 2023 20:15
@sentry-io
Copy link

sentry-io bot commented Aug 1, 2023

Suspect Issues

This pull request has been deployed and Sentry has observed the following issues:

  • ‼️ **syscall.Errno: <redacted errors.withStack>: <redacted fs.PathError>: go.jetpack.io/devbox/internal/wrapnix in Create... View Issue

Did you find this useful? React with a 👍 or 👎

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