You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fs.existsSync returns wrong value on windows if there are no permissions on the given file #17921
Disable permissions inheritance and remove all inherited permissions from the file
Execute fs.existsSync('1.txt')
What is the expected behavior
The file exists (and it is also listed if you readdirSync it's parent directory), so the return value should be true.
What went wrong
The return value is false, like the file doesn't exist. If it is working as intended, then consider this issue as a feature request. However, if you're not aware of this behavior, then I'm pretty sure it is a bug.
Perhaps the documentation could be improved (I'll add the label) but fs.exists() works the same way as fs.stat() in this regard: it queries the operating system for file metadata for the specified path and passes on the error that the operating system returns.
The difference is that fs.stat() would have returned an error whereas fs.exists() returns false because true or false is the only thing it's allowed to return.
You might get better results with fs.access(), depending on the situation.
bin
C:\Users\XXX\.appcelerator\install\7.0.1\package\bin\appc
fs.existsSync(bin)
true
fs.accessSync(bin)
undefined
I put a while(true) {} to stop at that very stage but if I run >cd C:\Users\XXX\.appcelerator in parallel the output is: The system cannot find the path specified.
I am the reporter of this issue, but I accidentally deleted my account.
@bnoordhuis So, this actually works as intended? Ok, then it would be a good idea to mention it somewhere in the doc. Or, even better, change the behavior of fs.existsSync to try to read parent dir in case of error and if the file is located in the parent dir, then return true, no matter if the actual file is accessible or not.
@Johnsavadkuhi What does your thumbs down mean: you cannot reproduce the issue, or you disagree that this issue should be considered as a bug? "Let me to see your code" - my code or @jaulz's code?
In this case existsSync call to stat fails with EPERM, maybe we could make existsSync return false when the error is ENOENT? Or, is there a reason why existsSync does not use accessSync?
I'm using NodeJS v11.10.0 on Windows 10 and having the same issue: existsSync says a file does not exist but it does and I do have permissions on it. What to do?
@cawoodm you probably want to either use fs.accessSync or you directly want to call fs.open as recommended in the documentation.
There is no guarantee that the file does not exist if fs.existsSync returns false. It only let's you know if the file is there and is accessible for you. There could be multiple reasons for the cause in case it returns false.
Sorry to comment on a closed issue but I'm seeing the same thing.
OS: Windows 10
Node version: 13.12.0
The file in question is java installed via scoop C:\Users\Oliver\scoop\apps\openjdk11\current\bin\java. It has permissions and definitely exists but existsSync returns false!
Calling accessSync returns this error:
Error: ENOENT: no such file or directory, access 'C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java'
at Object.accessSync (fs.js:208:3) {
errno: -4058,
syscall: 'access',
code: 'ENOENT',
path: 'C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java'
}
Finally got to the bottom of this. Windows has to have the extension of the file in order to check that it exists so fs.existsSync('C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java.exe') works but fs.existsSync('C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java') doesn't
Reacted by Justin M. Keyes
Reacted by solartes, Guillermo Cortés, SuppliedOrange, IonDev and Ricardo Romero
Activity
jaulz commentedon Jan 17, 2018
I have a similar issue where
existsSyncreturns true though the file does not exist. Happens on Windows 10 with NodeJS v8.9.1.Johnsavadkuhi commentedon Jan 17, 2018
let me to see your code
bnoordhuis commentedon Jan 17, 2018
Perhaps the documentation could be improved (I'll add the label) but
fs.exists()works the same way asfs.stat()in this regard: it queries the operating system for file metadata for the specified path and passes on the error that the operating system returns.The difference is that
fs.stat()would have returned an error whereasfs.exists()returns false because true or false is the only thing it's allowed to return.You might get better results with
fs.access(), depending on the situation.jaulz commentedon Jan 17, 2018
Following the code I use:
This is the output:
I put a
while(true) {}to stop at that very stage but if I run>cd C:\Users\XXX\.appceleratorin parallel the output is:The system cannot find the path specified.Any idea?
bnoordhuis commentedon Jan 17, 2018
@jaulz That's probably some ACL or permissions issue. The directory is there, it's just inaccessible.
jaulz commentedon Jan 18, 2018
@bnoordhuis not sure... I cannot even find that folder via command nor via explorer.
6-8-axnw1bom81v5xa3nh48c commentedon Jan 20, 2018
I am the reporter of this issue, but I accidentally deleted my account.
@bnoordhuis So, this actually works as intended? Ok, then it would be a good idea to mention it somewhere in the doc. Or, even better, change the behavior of
fs.existsSyncto try to read parent dir in case of error and if the file is located in the parent dir, then returntrue, no matter if the actual file is accessible or not.@Johnsavadkuhi What does your thumbs down mean: you cannot reproduce the issue, or you disagree that this issue should be considered as a bug? "Let me to see your code" - my code or @jaulz's code?
bzoz commentedon Feb 1, 2018
In this case
existsSynccall tostatfails withEPERM, maybe we could makeexistsSyncreturn false when the error isENOENT? Or, is there a reason whyexistsSyncdoes not useaccessSync?bnoordhuis commentedon Feb 1, 2018
fs.existsSync()always returns false when the stat fails.Yes, see #4679 - Windows CI issue.
fs: use fs.access in fs.exists
fs: use fs.access in fs.exists
fs: use fs.access in fs.exists
fs: use fs.access in fs.exists
cawoodm commentedon Mar 27, 2019
I'm using NodeJS v11.10.0 on Windows 10 and having the same issue: existsSync says a file does not exist but it does and I do have permissions on it. What to do?
BridgeAR commentedon Mar 27, 2019
@cawoodm you probably want to either use
fs.accessSyncor you directly want to callfs.openas recommended in the documentation.There is no guarantee that the file does not exist if
fs.existsSyncreturnsfalse. It only let's you know if the file is there and is accessible for you. There could be multiple reasons for the cause in case it returnsfalse.cawoodm commentedon Mar 30, 2019
Oops, I think my problem was with backslashes in the path
C:\tempbeing interpreted as tabs. Sorry for jostling!ohuu commentedon May 4, 2020
Sorry to comment on a closed issue but I'm seeing the same thing.
OS: Windows 10
Node version: 13.12.0
The file in question is
javainstalled via scoopC:\Users\Oliver\scoop\apps\openjdk11\current\bin\java. It has permissions and definitely exists butexistsSyncreturns false!Calling
accessSyncreturns this error:calling
openreturnsundefined.ohuu commentedon May 7, 2020
Finally got to the bottom of this. Windows has to have the extension of the file in order to check that it exists so
fs.existsSync('C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java.exe')works butfs.existsSync('C:/Users/Oliver/scoop/apps/openjdk11/current/bin/java')doesn'tbadrelmers commentedon Mar 23, 2022
this is really a stupid language
fs: use fs.access in fs.exists