From baaae5fa9a543399eeea8165b062268babb7a0fe Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 29 Sep 2020 13:06:43 +0800 Subject: [PATCH 1/2] fs: simplify realpathSync --- lib/fs.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 67a050b4e8c480..fd609efab83ab6 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1598,10 +1598,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 += ''; From 2177cf65f3fc90f6766808b8421cd8a97abecb30 Mon Sep 17 00:00:00 2001 From: himself65 Date: Tue, 29 Sep 2020 21:26:10 +0800 Subject: [PATCH 2/2] fixup! more simplify --- lib/fs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index fd609efab83ab6..26ceaba5260dd6 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1630,7 +1630,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); @@ -1828,7 +1828,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) => { @@ -1841,7 +1841,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));