mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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:
11
lib/fs.js
11
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 += '';
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user