Skip to content
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

Merged
merged 2 commits into from
Sep 19, 2018

Conversation

justone
Copy link
Contributor

@justone justone commented Sep 18, 2018

This searches the following in preferred order:

  1. Local directory
  2. $GOPATH/bin
  3. In $PATH

@justone
Copy link
Contributor Author

justone commented Sep 18, 2018

cc/ @swgillespie

This searches the following in preferred order:

1. Local directory
2. $GOPATH/bin
3. In $PATH
@swgillespie swgillespie self-requested a review September 18, 2018 22:54
@swgillespie
Copy link
Contributor

Linking issues: #1614


cwdProgram := filepath.Join(cwd, program)
if _, err := os.Stat(cwdProgram); !os.IsNotExist(err) {
logging.V(5).Infoln("program %s found in CWD", program)
Copy link
Contributor

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.

Copy link
Contributor

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.

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

Choose a reason for hiding this comment

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

Same here re: directories.

Copy link
Contributor

@swgillespie swgillespie left a 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!

@justone
Copy link
Contributor Author

justone commented Sep 19, 2018

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

@swgillespie
Copy link
Contributor

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?

Nah, I think this is fine - I don't think we need to go that far.

Copy link
Contributor

@swgillespie swgillespie left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@swgillespie swgillespie merged commit 88efd73 into pulumi:master Sep 19, 2018
@justone justone deleted the improve-go-program-search branch September 19, 2018 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants