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

handle tilde expansion for OS home directory #249

Closed
wants to merge 1 commit into from

Conversation

cicorias
Copy link
Member

@cicorias cicorias commented Jun 1, 2017

this is related to microsoft/azure-pipelines-tasks#4302

This handles tilde ~ expansion for bash shells where the PATH has a tilde such as ~/bin.

Since node's fs.statSync doesn't expand tilde's, See this conversation as well as to why node team didn't fix. nodejs/node#684 (comment)

@ericsciple
Copy link
Contributor

I tried this from a shell script (one script calls another script) and it resolves ~ in the paths. So I think adding support for this probably makes sense. At first I was confused at the motivation - I originally assumed it was primarily only supported interactively by the bash shell.

node/internal.ts Outdated
@@ -426,7 +427,7 @@ export function _which(tool: string, check?: boolean): string {
function _tryGetExecutablePath(filePath: string, extensions: string[]): string {
try {
// test file exists
let stats: fs.Stats = fs.statSync(filePath);
let stats: fs.Stats = fs.statSync(_unTildify(filePath));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since untildify is only run on that path that is stat'd and not the path that is returned, wouldn't which ultimately return the "wrong" tildified path?

Copy link
Member Author

Choose a reason for hiding this comment

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

filePath in tryGetExe is the segment of the PATH env variable which is what would be prefixed with a tilde.

It's fs.statSync that fails if there is a tilde. See the Node issue where they won't fix

So untildify just expands tilde only when it's a prefix as that should only be the case

All the Tests pass which include tests for running ls, grep, etc

Copy link
Contributor

Choose a reason for hiding this comment

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

If someone calls tl.which('sometool') and it returns a tildified-file-path, won't that cause problem depending on what the path is then used for? For instance, if they stat or lstat it will blow up. I would imagine other things may error as well.

I think it would make more sense to do this in the which function when iterating over the directories. And probably only when home is truthy and process.platform != 'win32' and the dir is ~ or starts with ~/. Also I noticed the regex below also handles ~\ which doesn't seem correct to me.

Also I'm curious if you have insight into how common this problem is? The stance node took is interesting, and I think makes sense for node. However, since the task lib exposes a which() function, it makes me feel like we have a better argument to add it (pragmatic reasoning to avoid common confusion).

Copy link
Member Author

Choose a reason for hiding this comment

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

let me add some tests that deal with these conditions and take it from there. The regex was taken directly from that library referenced by many in the Node issue.

Please stand by....

Copy link
Member Author

Choose a reason for hiding this comment

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

also, within the past week 2 other people using the AZ CLI ran into this problem on macOS. It's fairly routine in .bash_profile to rely on bash support of ~ instead of something like $HOME

Copy link
Member Author

Choose a reason for hiding this comment

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

This is going to take longer as ultimately it's let stats: fs.Stats = fs.statSync(filePath); that is failing, yet in each block the ENOENT exception is being eaten, so it passes. Some of these might valid; that's what I have to investigate. e.g.. https://github.com/Microsoft/vsts-task-lib/blob/master/node/internal.ts#L453 and https://github.com/Microsoft/vsts-task-lib/blob/master/node/internal.ts#L495

Copy link
Contributor

Choose a reason for hiding this comment

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

thats why i dont want which() to return the tildified path :). the dir should be untildified before it's joined with the file name to construct the candidate full path.

@yahavi
Copy link

yahavi commented Aug 30, 2018

Is there anything new with that?

@damccorm
Copy link

damccorm commented Feb 1, 2019

I'm going to close this since there hasn't been progress for a year and a half, please reopen if appropriate. If people are still experiencing issues from this, lets log an issue and move forward from there. @cicorias if you're planning on continuing work on this, feel free to reopen here or start a new PR.

@damccorm damccorm closed this Feb 1, 2019
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.

6 participants