Skip to content

Commit

Permalink
fs: simplify realpathSync
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
himself65 authored and MylesBorins committed Nov 16, 2020
1 parent 0a1474d commit 19d7113
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions lib/fs.js
Expand Up @@ -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 += '';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) => {
Expand All @@ -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));
Expand Down

0 comments on commit 19d7113

Please sign in to comment.