-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Search for Go project executables in more places than just $PATH #1955
Conversation
cc/ @swgillespie |
This searches the following in preferred order: 1. Local directory 2. $GOPATH/bin 3. In $PATH
Linking issues: #1614 |
sdk/go/pulumi-language-go/main.go
Outdated
|
||
cwdProgram := filepath.Join(cwd, program) | ||
if _, err := os.Stat(cwdProgram); !os.IsNotExist(err) { | ||
logging.V(5).Infoln("program %s found in CWD", program) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to check here that what we found is actually an executable (i.e. it has the executable bit set and it's not a directory) - otherwise we're probably going to get a bad error message later on when we try to execute it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not sure Go exposes the executable bit, so I'd be fine just checking that it's not a directory.
sdk/go/pulumi-language-go/main.go
Outdated
if goPath := os.Getenv("GOPATH"); len(goPath) > 0 { | ||
goPathProgram := filepath.Join(goPath, "bin", program) | ||
if _, err := os.Stat(goPathProgram); !os.IsNotExist(err) { | ||
logging.V(5).Infoln("program %s found in $GOPATH/bin", program) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re: directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me, just a few nitpicks - thanks!
@swgillespie can you take another look? I check if the found path is a directory. Go does expose the permission bits, but they are not terribly easy to use. We could introduce permbits as a dependency, as that nicely wraps the underlying data. Should I go down that road? Another thought: because just being executable for someone doesn't necessarily mean executable for the current user. That would be a much deeper check. |
Nah, I think this is fine - I don't think we need to go that far. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
This searches the following in preferred order: