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

statSync fails in detecting link #47633

Closed
FStefanni opened this issue Apr 20, 2023 · 5 comments · Fixed by #47654
Closed

statSync fails in detecting link #47633

FStefanni opened this issue Apr 20, 2023 · 5 comments · Fixed by #47654
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors.

Comments

@FStefanni
Copy link

Version

v18.15.0

Platform

Linux debian 6.1.0-7-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.20-2 (2023-04-08) x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Just call statSync() on node_modules/.bin/mocha:

import fs from "node:fs"

const mocha = "<abs path>/node_modules/.bin/mocha";
const stat = fs.statSync(mocha);
console.log(`File: ${stat.isFile()}, Link: ${stat.isSymbolicLink()}`);

Result:

File: true, Link: false

But if I run in bash:

ls -l <abs path>/node_modules/.bin/mocha
stat <abs path>/node_modules/.bin/mocha

Result:

lrwxrwxrwx 1 user group 21 20 apr 08.33 <abs path>/node_modules/.bin/mocha -> ../mocha/bin/mocha.js

File: <abs path>/node_modules/.bin/mocha -> ../mocha/bin/mocha.js
Size: 21        	Blocks: 0          IO Block: 4096   symbolic link
Device: 259,2	Inode: 14118017    Links: 1
Access: (0777/lrwxrwxrwx)  Uid: ( 1000/   user)   Gid: ( 1000/   group)
Access: 2023-04-20 08:54:29.337525872 +0200
Modify: 2023-04-20 08:33:01.270951671 +0200
Change: 2023-04-20 08:33:01.270951671 +0200
 Birth: 2023-04-20 08:33:01.270951671 +0200

So it is truly a symbolic link.

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

it should say that it is a link and not a regular file

What do you see instead?

It says it is a regular file

Additional information

No response

@targos
Copy link
Member

targos commented Apr 20, 2023

fs.stat follows symlinks. You need to call lstat if you don't want this behavior

@targos targos added doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. labels Apr 20, 2023
@FStefanni
Copy link
Author

Hi,

yes you are right I missed it in the doc.
Maybe it is possible to explicitly write this in the documentation of all stat() function variants (stat, promises.stat(), etc.), so it will be clearer? (I suppose the "doc" tag of this issue means exactly this :) )

Regards

@targos
Copy link
Member

targos commented Apr 20, 2023

I think it would be helpful to mention it directly in the documentation, yes.

@targos targos added the good first issue Issues that are suitable for first-time contributors. label Apr 20, 2023
@amitanshusahu
Copy link

hey @targos , i would like to work on it if its open, can i git this assigned :)

@mertcanaltin
Copy link
Member

mertcanaltin commented Apr 20, 2023

@targos I tried to make an edit

nodejs-github-bot pushed a commit that referenced this issue Apr 23, 2023
PR-URL: #47654
Fixes: #47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 28, 2023
PR-URL: nodejs#47654
Fixes: nodejs#47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 28, 2023
PR-URL: nodejs#47654
Fixes: nodejs#47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
yjl9903 pushed a commit to yjl9903/node that referenced this issue Apr 29, 2023
PR-URL: nodejs#47654
Fixes: nodejs#47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
targos pushed a commit that referenced this issue May 2, 2023
PR-URL: #47654
Fixes: #47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
danielleadams pushed a commit that referenced this issue Jul 6, 2023
PR-URL: #47654
Fixes: #47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
MoLow pushed a commit to MoLow/node that referenced this issue Jul 6, 2023
PR-URL: nodejs#47654
Fixes: nodejs#47633
Reviewed-By: Darshan Sen <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Daeyeon Jeong <[email protected]>
Reviewed-By: LiviaMedeiros <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. good first issue Issues that are suitable for first-time contributors.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants