fs: simplify realpathSync

PR-URL: https://github.com/nodejs/node/pull/35413
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
himself65
2020-09-29 13:06:43 +08:00
committed by Luigi Pinca
parent 5c5d044de0
commit b8f34b295c

View File

@@ -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 += '';
@@ -1633,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);
@@ -1831,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) => {
@@ -1844,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));