Skip to content

fs.existSync returns true after fs. symlinkSync node 10 onwards in windows only #30538

Description

@SparshithNR

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 :)

Activity

  1. pd4d10 commented on Nov 19, 2019

    @pd4d10
    Contributor

    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.

  2. pd4d10 commented on Nov 19, 2019

    @pd4d10
    Contributor

    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

  3. SparshithNR commented on Nov 19, 2019

    @SparshithNR
    Author

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

  4. Fishrock123 commented on Nov 19, 2019

    @Fishrock123
    Contributor

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

  5. added
    fsIssues and PRs related to file-system APIs and the fs module.
    windowsIssues and PRs related to the Windows platform.
    on Nov 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to file-system APIs and the fs module.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions