From 19d711391e56150860be601ddcad1a48bc51acec Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 29 Sep 2020 13:06:43 +0800 Subject: [PATCH] fs: simplify realpathSync PR-URL: https://github.com/nodejs/node/pull/35413 Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: Rich Trott Reviewed-By: James M Snell --- lib/fs.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index eead8bb5a39176..8196e694ae7bd4 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1566,10 +1566,7 @@ if (isWindows) { const emptyObj = ObjectCreate(null); function realpathSync(p, options) { - if (!options) - options = emptyObj; - else - options = getOptions(options, emptyObj); + options = getOptions(options, emptyObj); p = toPathIfFileURL(p); if (typeof p !== 'string') { p += ''; @@ -1601,7 +1598,7 @@ function realpathSync(p, options) { pos = current.length; // On windows, check that the root exists. On unix there is no need. - if (isWindows && !knownHard[base]) { + if (isWindows) { const ctx = { path: base }; binding.lstat(pathModule.toNamespacedPath(base), false, undefined, ctx); handleErrorFromBinding(ctx); @@ -1799,7 +1796,7 @@ function realpath(p, options, callback) { const ino = stats.ino.toString(32); id = `${dev}:${ino}`; if (seenLinks[id]) { - return gotTarget(null, seenLinks[id], base); + return gotTarget(null, seenLinks[id]); } } fs.stat(base, (err) => { @@ -1812,7 +1809,7 @@ function realpath(p, options, callback) { }); } - function gotTarget(err, target, base) { + function gotTarget(err, target) { if (err) return callback(err); gotResolvedLink(pathModule.resolve(previous, target));