summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRongjian Zhang <pd4d10@gmail.com>2019-11-22 14:01:21 +0800
committerAnna Henningsen <anna@addaleax.net>2019-12-03 23:48:08 +0100
commit0e3d774ed21375675b024f555a67773821e56a9d (patch)
tree40b8710c72e8adab75dbae5632c81a76f715667c /lib
parent3ebae6cf1b20ce104423214d75c3c84129a8f141 (diff)
downloadandroid-node-v8-0e3d774ed21375675b024f555a67773821e56a9d.tar.gz
android-node-v8-0e3d774ed21375675b024f555a67773821e56a9d.tar.bz2
android-node-v8-0e3d774ed21375675b024f555a67773821e56a9d.zip
fs: fix existsSync for invalid symlink at win32
Fixes: https://github.com/nodejs/node/issues/30538 PR-URL: https://github.com/nodejs/node/pull/30556 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/fs.js b/lib/fs.js
index b7ada86c28..baf418c4b0 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -234,7 +234,16 @@ function existsSync(path) {
return false;
}
const ctx = { path };
- binding.access(pathModule.toNamespacedPath(path), F_OK, undefined, ctx);
+ const nPath = pathModule.toNamespacedPath(path);
+ binding.access(nPath, F_OK, undefined, ctx);
+
+ // In case of an invalid symlink, `binding.access()` on win32
+ // will **not** return an error and is therefore not enough.
+ // Double check with `binding.stat()`.
+ if (isWindows && ctx.errno === undefined) {
+ binding.stat(nPath, false, undefined, ctx);
+ }
+
return ctx.errno === undefined;
}