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

On Windows, node inconsistently capitalizes drive letters when resolving junctions #38459

Closed
xirzec opened this issue Apr 28, 2021 · 2 comments
Closed
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@xirzec
Copy link

xirzec commented Apr 28, 2021

  • Version: v14.16.0
  • Platform: Microsoft Windows NT 10.0.19042.0 x64
  • Subsystem: fs

What steps will reproduce the bug?

Create a small repro directory that contains a junction from one folder to another and create a simple source file:

mkdir C:\repro-realpath-bug
mkdir C:\repro-realpath-bug\src
mklink /J "C:\repro-realpath-bug\link" "C:\repro-realpath-bug\src"
echo console.log('hello world!'); >> "C:\repro-realpath-bug\src\index.js"

Now enter the directory and try using realpath:

cd c:\repro-realpath-bug
node
> fs.realpathSync("./src/index.js")
'c:\\repro-realpath-bug\\src\\index.js'
> fs.realpathSync("./link/index.js")
'C:\\repro-realpath-bug\\src\\index.js'

Notice the link drive letter is capitalized (as the junction target drive letter is capitalized) but targeting the file directly gives us a lowercased drive letter (that matches the cd command target).

If you do cd C:\repro-realpath-bug however, they will match.

What is the expected behavior?

Regardless of the path to get to the real file, the drive letter casing matches what is in process.cwd(), like when following a relative path.

What do you see instead?

When following a junction, the path casing changes to whatever the junction target uses

Additional information

Note that this bug works the other way too, if you create the junction with a lowercase drive letter

mklink /J "c:\repro-realpath-bug\link2" "c:\repro-realpath-bug\src"
C:\repro-realpath-bug> node
> fs.realpathSync("./link2/index.js")
'c:\\repro-realpath-bug\\src\\index.js'
@xirzec
Copy link
Author

xirzec commented Apr 28, 2021

Forgot to mention, #6624 has some interesting prior art with bugs in this space.

As to how I hit this - our monorepo uses rush which symlinks node_modules and rollup was having trouble resolving modules through the junction.

@Ayase-252 Ayase-252 added the fs Issues and PRs related to the fs subsystem / file system. label Apr 29, 2021
@jasnell jasnell added the windows Issues and PRs related to the Windows platform. label Apr 30, 2021
@StefanStojanovic
Copy link
Contributor

This has been stale for a long time. Based on the investigation, the main reason for the inconsistency is the DeviceIOControl Windows API call, more precisely the values it returns. Because of all of this, I'm closing the issue. Feel free to reopen if needed.

@StefanStojanovic StefanStojanovic closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

4 participants