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

fs.realpathSync('') returns CWD #35403

Open
drsm opened this issue Sep 28, 2020 · 3 comments
Open

fs.realpathSync('') returns CWD #35403

drsm opened this issue Sep 28, 2020 · 3 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@drsm
Copy link

drsm commented Sep 28, 2020

$ node -v
v12.18.4

What steps will reproduce the bug?

$ cd /tmp
$ node -e "console.log(fs.realpathSync(''))"
/tmp

What is the expected behavior?

$ node -e "fs.realpath.native('', (e) => void console.log(e))"
[Error: ENOENT: no such file or directory, realpath ''] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'realpath',
  path: ''
}
@ChALkeR
Copy link
Member

ChALkeR commented Sep 28, 2020

For more context:

  • fs.promises.realpath('') returns a rejection with ENOENT.
  • fs.realpath('', (...args) => console.log(args)) passes null, CWD to the callback.
  • fs.realpathSync('') returns CWD.

@ChALkeR ChALkeR added the fs Issues and PRs related to the fs subsystem / file system. label Sep 28, 2020
@bnoordhuis
Copy link
Member

That output kind of makes sense, knowing what I know about how fs.realpath() is implemented, but it behaves differently on Windows so we should make a judgment call on what we think is the appropriate behavior.

fs.promises.realpath('') returns a rejection with ENOENT.

That's because it's a wrapper around fs.realpath.native rather than fs.realpath. No idea why.

@drsm
Copy link
Author

drsm commented Sep 30, 2020

here is some more on this:

> fs.realpath(Buffer.from([]), (e, p) => console.log([e && e.path, p]))
undefined
> [ null, '/tmp' ]

> fs.realpath.native(Buffer.from([]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '', undefined ]

> fs.realpath(Buffer.from([1]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '/tmp/\u0001', undefined ]

> fs.realpath.native(Buffer.from([1]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '\u0001', undefined ]

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.
Projects
None yet
Development

No branches or pull requests

3 participants