diff --git a/doc/api/fs.markdown b/doc/api/fs.markdown index 20aef1147f0157..2d5d6901485d70 100644 --- a/doc/api/fs.markdown +++ b/doc/api/fs.markdown @@ -367,11 +367,14 @@ non-existent. ## fs.existsSync(path) - Stability: 0 - Deprecated: Use [fs.statSync][] or [fs.accessSync][] instead. - Synchronous version of [`fs.exists`][]. Returns `true` if the file exists, `false` otherwise. +Note: this function will throw on Windows if an EPERM error is returned by the +underlying `fs.statSync()` call. However, it is not suggested to attempt to +catch this error. Instead, the end user probably needs to fix the file's +permissions by hand. + ## fs.fchmod(fd, mode, callback) Asynchronous fchmod(2). No arguments other than a possible exception diff --git a/lib/fs.js b/lib/fs.js index 650ede67af8bae..1a19aa2a18c500 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -223,6 +223,9 @@ fs.existsSync = function(path) { binding.stat(pathModule._makeLong(path)); return true; } catch (e) { + if (e.code === 'EPERM') + throw e; // EPERM means we no longer knows if it exists or not. + return false; } };