-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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.existsSync(brokenSymlink) returns false #14025
Comments
Sounds logical to me. |
Yes, it's expected; symlinks are supposed to be transparent. I'll close the issue. |
Er.. so how do I test for the existence of a broken symlink? |
@kingces95 You can use |
Hi, sorry to resurrect this thread - I'm finding myself in need of something similar: I am trying to move a file to NEW_PATH, and if NEW_PATH already exists, the operation will fail. The naive solution is to do something like:
However, this will break if NEW_PATH is a broken symlink (b/c exists will return false, and move will fail), which doesn't feel super intuitive and potentially like a quick way for library authors to shoot themselves in the foot (as not everyone will be thinking about the case where there are broken symlinks). Is there a function that is better suited than existsSync()? Or is there a more straightforward way than putting a try-catch around lstat(NEW_PATH)? Or is the belief that it is the correct behavior for libraries to fail here? If those aren't the case, thoughts on adding a flag to existsSync options to check for symlinks? Or possibly a pathExists() method? |
You could not use
You might want to be more specific about the error you’re seeing, because
I’d be against that – you already came up with good alternatives :) |
Appreciate it! And unlinking unconditionally is a good idea :) I believe I was doing a copy, not a move--my mistake--, and that broke b/c it was trying to dereference the path. Thank you! |
fs.existsSync(linkName)
returns false whenlinkName
is a broken symbolic link path(whose target does not exist).Is the result by design or like a bug?
The text was updated successfully, but these errors were encountered: