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

Fallback to process cwd when resolving drive cwd #8541

Closed
wants to merge 2 commits into from

Conversation

jasongin
Copy link
Member

@jasongin jasongin commented Sep 14, 2016

Checklist
  • vcbuild test nosign (Windows) passes (Some tests failed, but they're unrelated: the failures repro without this change.)
  • tests and/or benchmarks are included
  • documentation is changed or added (N/A - path.resolve's Windows drive-letter-specific behavior is not documented. Should it be?)
  • commit message follows commit guidelines
Affected core subsystem(s)

path

Description of change

The path.resolve() function when given just a drive letter such as "C:" tries to get a drive-specific CWD, but that isn't available in cases when the process is not launched via cmd.exe and the process CWD has not been explicitly set on that drive.

This change adds a fallback to the process CWD, if the process CWD happens to be on the resolved drive letter. If the process CWD is on another drive, then a drive-specific CWD cannot be resolved and defaults to the drive's root as before.

Based on experimentation, the fixed behavior matches that of other similar path resolution implementations on Windows I checked: .NET's System.IO.Path.GetFullPath() and Python's os.path.abspath().

Fixes: #7215

@nodejs-github-bot nodejs-github-bot added the path Issues and PRs related to the path subsystem. label Sep 14, 2016
@mscdex mscdex added the windows Issues and PRs related to the Windows platform. label Sep 14, 2016
@Trott
Copy link
Member

Trott commented Sep 14, 2016

Are you able to add a test for this?

The `path.resolve()` function when given just a drive letter such as
"C:" tries to get a drive-specific CWD, but that isn't available in
cases when the process is not launched via cmd.exe and the process
CWD has not been explicitly set on that drive.

This change adds a fallback to the process CWD, if the process CWD
happens to be on the resolved drive letter. If the process CWD is on
another drive, then a drive-specific CWD cannot be resolved and
defaults to the drive's root as before.

Based on experimentation, the fixed behavior matches that of other
similar path resolution implementations on Windows I checked: .NET's
`System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`.

In the automated path test cases the issue doesn't occur when the
tests are run normally from cmd.exe. But it did cause an assertion
when running the tests from PowerShell, that is fixed by this change.

Fixes: nodejs#7215
@jasongin
Copy link
Member Author

@Trott OK, I added a test.

@Trott
Copy link
Member

Trott commented Sep 15, 2016

@nodejs/platform-windows (helps to look at #7215 for context of the problem too)

Copy link
Contributor

@bzoz bzoz left a comment

Choose a reason for hiding this comment

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

LGTM

@Trott
Copy link
Member

Trott commented Sep 16, 2016

Are there probable semver implications to this? Might a Windows CIGTM run be in order? Or would that be a bit much?

@gibfahn
Copy link
Member

gibfahn commented Sep 16, 2016

@Trott Is citgm on windows currently working? Judging from the current status of nodejs/citgm#157 I'd assume not.

@Trott
Copy link
Member

Trott commented Sep 16, 2016

@gibfahn Ugh, yes, you appear to be correct. I don't see any Windows hosts at https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/. Oh well.

Anyway, are there likely semver implications here? Seems like "probably not" to me, but I'm not exacxtly Windows-savvy.

@jasnell
Copy link
Member

jasnell commented Sep 20, 2016

@joshgav and @saghul ... would either of you be able to weigh in on this?

@saghul
Copy link
Member

saghul commented Sep 20, 2016

@jasnell I'm afraid I'm not that familiar with what Windows does in this case :-S @bzoz gave it a thumbs up so I trust him, he has been doing good work fixing Windows issues.

@jasongin
Copy link
Member Author

The previous behavior was objectively wrong/buggy, because it would (sometimes!) resolve "C:" to "C:" when the current working directory was "C:\path...".

It is remotely possible that some user code relied on that buggy behavior. However I think that's extremely unlikely because the bug was not even consistent: it only occurred in a spawned process and only if the process cwd had not been explicitly set. So in my opinion this should probably not be considered a breaking change.

@jasnell
Copy link
Member

jasnell commented Sep 20, 2016

That works for me! LGTM

@joaocgreis
Copy link
Member

This might be a bit of a gray area because behavior changes, but I completely agree with @jasongin that this is a bug fix. I cannot think of any situation where good code would break because of this.

@jasnell
Copy link
Member

jasnell commented Sep 22, 2016

@imyller imyller self-assigned this Sep 23, 2016
@imyller
Copy link
Member

imyller commented Sep 23, 2016

Landing:

  • Two LGTMs
  • No objections
  • Requested changes have been made
  • CI test passed (only the known CI failures)

imyller pushed a commit to imyller/node that referenced this pull request Sep 23, 2016
The `path.resolve()` function when given just a drive letter such as
"C:" tries to get a drive-specific CWD, but that isn't available in
cases when the process is not launched via cmd.exe and the process
CWD has not been explicitly set on that drive.

This change adds a fallback to the process CWD, if the process CWD
happens to be on the resolved drive letter. If the process CWD is on
another drive, then a drive-specific CWD cannot be resolved and
defaults to the drive's root as before.

Based on experimentation, the fixed behavior matches that of other
similar path resolution implementations on Windows I checked: .NET's
`System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`.

In the automated path test cases the issue doesn't occur when the
tests are run normally from cmd.exe. But it did cause an assertion
when running the tests from PowerShell, that is fixed by this change.

PR-URL: nodejs#8541
Fixes: nodejs#7215
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@imyller
Copy link
Member

imyller commented Sep 23, 2016

landed in 0f2f8ef

Thank you for your contribution, @jasongin

@imyller imyller closed this Sep 23, 2016
@imyller imyller removed their assignment Sep 23, 2016
jasnell pushed a commit that referenced this pull request Sep 29, 2016
The `path.resolve()` function when given just a drive letter such as
"C:" tries to get a drive-specific CWD, but that isn't available in
cases when the process is not launched via cmd.exe and the process
CWD has not been explicitly set on that drive.

This change adds a fallback to the process CWD, if the process CWD
happens to be on the resolved drive letter. If the process CWD is on
another drive, then a drive-specific CWD cannot be resolved and
defaults to the drive's root as before.

Based on experimentation, the fixed behavior matches that of other
similar path resolution implementations on Windows I checked: .NET's
`System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`.

In the automated path test cases the issue doesn't occur when the
tests are run normally from cmd.exe. But it did cause an assertion
when running the tests from PowerShell, that is fixed by this change.

PR-URL: #8541
Fixes: #7215
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins
Copy link
Contributor

I'm going to make the assumption that v4.x is not affected by this as this patch is not landing cleanly. If I am mistaken please feel free to backport

@saghul
Copy link
Member

saghul commented Oct 7, 2016

@thealphanerd I believe it is affected as well. That code hasn't changed and it not related to any of the realpath stuff since we are now back on the JS implementation.

Fishrock123 pushed a commit that referenced this pull request Oct 11, 2016
The `path.resolve()` function when given just a drive letter such as
"C:" tries to get a drive-specific CWD, but that isn't available in
cases when the process is not launched via cmd.exe and the process
CWD has not been explicitly set on that drive.

This change adds a fallback to the process CWD, if the process CWD
happens to be on the resolved drive letter. If the process CWD is on
another drive, then a drive-specific CWD cannot be resolved and
defaults to the drive's root as before.

Based on experimentation, the fixed behavior matches that of other
similar path resolution implementations on Windows I checked: .NET's
`System.IO.Path.GetFullPath()` and Python's `os.path.abspath()`.

In the automated path test cases the issue doesn't occur when the
tests are run normally from cmd.exe. But it did cause an assertion
when running the tests from PowerShell, that is fixed by this change.

PR-URL: #8541
Fixes: #7215
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
path Issues and PRs related to the path subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent resolution of path "C:" with spawn on Windows