Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions internal/wrapnix/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func CreateWrappers(ctx context.Context, args CreateWrappersArgs) error {
_ = os.MkdirAll(destPath, 0o755)

bashPath := cmdutil.GetPathOrDefault("bash", "/bin/bash")
sedPath := cmdutil.GetPathOrDefault("sed", "sed")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Won't the default value trigger the bug again? Should the default be /usr/bin/sed to mirror /bin/bash above?

Copy link
Contributor Author

@mikeland73 mikeland73 Oct 18, 2023

Choose a reason for hiding this comment

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

Yeah if sed is not in path this will trigger same issue. Though if sed is not in path the wrapper would have failed anyway. sed is POSIX so I kinda assume it exists. I can fix it, but

There's an additional problem that affects sed and bash. If you are using global and a project devbox and both install sed and/or bash, you could end up cycling between both wrappers recursivelly. For example:

  • Add coreutils to project (bin wrappers use /usr/bin/sed)
  • Add coreutils to global while shelled in to project (bin wrappers use sed in project)
  • Make some change to project, now sed in bin wrapper points to global sed
  • Cycle

Another edge case:

  • if 2 devbox processes are creating wrappers at the same time, theres a chance the second one will point to the bin wrapper incorrectly.

These are pretty edge cases, but would suck. I think a better solution is to just special case sed and bash and never bin wrap them. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Follow up #1571

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yeah, nested environments would throw everything off. I commented in the other PR with some ideas.


if err := CreateDevboxSymlinkIfPossible(); err != nil {
return err
Expand All @@ -58,6 +59,7 @@ func CreateWrappers(ctx context.Context, args CreateWrappersArgs) error {
WrapperBinPath: destPath,
CreateWrappersArgs: args,
BashPath: bashPath,
SedPath: sedPath,
Command: bin,
DevboxSymlinkDir: devboxSymlinkDir,
destPath: filepath.Join(destPath, filepath.Base(bin)),
Expand Down Expand Up @@ -128,6 +130,7 @@ func CreateDevboxSymlinkIfPossible() error {
type createWrapperArgs struct {
CreateWrappersArgs
BashPath string
SedPath string
Command string
destPath string
DevboxSymlinkDir string
Expand Down
2 changes: 1 addition & 1 deletion internal/wrapnix/wrapper.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ should be in PATH.
This is implemented in sed for efficiency. sed is POSIX so we assume it's available.

*/ -}}
export PATH=$(echo $PATH | sed -e 's#:{{ .WrapperBinPath }}##' -e 's#{{ .WrapperBinPath }}:##' -e 's#{{ .WrapperBinPath }}##')
export PATH=$(echo $PATH | {{ .SedPath }} -e 's#:{{ .WrapperBinPath }}##' -e 's#{{ .WrapperBinPath }}:##' -e 's#{{ .WrapperBinPath }}##')

exec {{ .Command }} "$@"