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.existSync returns true after fs. symlinkSync node 10 onwards in windows only #30538

Closed
SparshithNR opened this issue Nov 19, 2019 · 4 comments
Labels
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@SparshithNR
Copy link

Hi,
I started seeing a difference in behavior when I run the following code in Linux and Windows in node 10 and node 12.

const fs = require('fs');

console.log(`Before symlink: ${fs.existsSync('linkHere')}`);
fs.symlinkSync('test/foo.js', 'linkHere');
console.log(`After symlink: ${fs.existsSync('linkHere')}`);
console.log(`issymlink: ${fs.lstatSync('linkHere').isSymbolicLink()}`);
//cleanup
fs.unlinkSync('linkHere');

I created reproduction repo and travis, appveyor CI to show the difference.
Please check the output of the above snippet;

  • node 8
    • linux
$ node --version
v8.16.2
> node index.js
Before symlink: false
After symlink: false
issymlink: true
  • windows
$ node index.js
Before symlink: false
After symlink: false
issymlink: true
  • node 10
    • linux
$ node --version
v10.17.0
> node index.js
Before symlink: false
After symlink: false
issymlink: true
  • windows
Installing node 10.17.0 (x86)...
$ node index.js
Before symlink: false
After symlink: true
issymlink: true

I am not sure why are we getting different result for same code in windows and Linux? Is it a bug or am I missing something.
Reproduction repo: https://github.com/SparshithNR/node-symlink
Travis build: https://travis-ci.com/SparshithNR/node-symlink/builds/137133722
appveyor build: https://ci.appveyor.com/project/SparshithNR/node-symlink

Thank you in advance :)

@pd4d10
Copy link
Contributor

pd4d10 commented Nov 19, 2019

It seems reasonable at Linux, because the link is broken (There is no test/foo.js file)

If test/foo.js exists the second result would be true.

@pd4d10
Copy link
Contributor

pd4d10 commented Nov 19, 2019

The behavior of Windows seems caused by using access instead of stat to implement existsSync, See #18618

Maybe we should firstly add some tests to test-fs-exists.js to cover this case

@SparshithNR
Copy link
Author

@pd4d10 Thanks for the response. Should I consider this issue as a bug in the windows?

@Fishrock123
Copy link
Member

Perhaps exists should just check both access and stat on Windows...

@Fishrock123 Fishrock123 added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Nov 19, 2019
targos pushed a commit that referenced this issue Dec 9, 2019
Fixes: #30538

PR-URL: #30556
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jan 13, 2020
Fixes: #30538

PR-URL: #30556
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
BethGriggs pushed a commit that referenced this issue Feb 6, 2020
Fixes: #30538

PR-URL: #30556
Reviewed-By: Anna Henningsen <anna@addaleax.net>
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
fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants