lib: removed unnecessary fs.realpath options
arg check + tests
Removed duplicated check for options argument of fs.realpath. Added some tests which covering the cases for passing options arg as null. PR-URL: https://github.com/nodejs/node/pull/27909 Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
parent
ff4a71ccc3
commit
490c7e0606
@ -1533,11 +1533,9 @@ realpathSync.native = (path, options) => {
|
|||||||
|
|
||||||
function realpath(p, options, callback) {
|
function realpath(p, options, callback) {
|
||||||
callback = typeof options === 'function' ? options : maybeCallback(callback);
|
callback = typeof options === 'function' ? options : maybeCallback(callback);
|
||||||
if (!options)
|
options = getOptions(options, {});
|
||||||
options = emptyObj;
|
|
||||||
else
|
|
||||||
options = getOptions(options, emptyObj);
|
|
||||||
p = toPathIfFileURL(p);
|
p = toPathIfFileURL(p);
|
||||||
|
|
||||||
if (typeof p !== 'string') {
|
if (typeof p !== 'string') {
|
||||||
p += '';
|
p += '';
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,14 @@ function test_simple_error_callback(realpath, realpathSync, cb) {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_simple_error_cb_with_null_options(realpath, realpathSync, cb) {
|
||||||
|
realpath('/this/path/does/not/exist', null, common.mustCall(function(err, s) {
|
||||||
|
assert(err);
|
||||||
|
assert(!s);
|
||||||
|
cb();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function test_simple_relative_symlink(realpath, realpathSync, callback) {
|
function test_simple_relative_symlink(realpath, realpathSync, callback) {
|
||||||
console.log('test_simple_relative_symlink');
|
console.log('test_simple_relative_symlink');
|
||||||
if (skipSymlinks) {
|
if (skipSymlinks) {
|
||||||
@ -395,6 +403,7 @@ function test_up_multiple(realpath, realpathSync, cb) {
|
|||||||
|
|
||||||
assertEqualPath(realpathSync(abedabeda), abedabeda_real);
|
assertEqualPath(realpathSync(abedabeda), abedabeda_real);
|
||||||
assertEqualPath(realpathSync(abedabed), abedabed_real);
|
assertEqualPath(realpathSync(abedabed), abedabed_real);
|
||||||
|
|
||||||
realpath(abedabeda, function(er, real) {
|
realpath(abedabeda, function(er, real) {
|
||||||
assert.ifError(er);
|
assert.ifError(er);
|
||||||
assertEqualPath(abedabeda_real, real);
|
assertEqualPath(abedabeda_real, real);
|
||||||
@ -407,6 +416,48 @@ function test_up_multiple(realpath, realpathSync, cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Going up with .. multiple times with options = null
|
||||||
|
// .
|
||||||
|
// `-- a/
|
||||||
|
// |-- b/
|
||||||
|
// | `-- e -> ..
|
||||||
|
// `-- d -> ..
|
||||||
|
// realpath(a/b/e/d/a/b/e/d/a) ==> a
|
||||||
|
function test_up_multiple_with_null_options(realpath, realpathSync, cb) {
|
||||||
|
console.error('test_up_multiple');
|
||||||
|
if (skipSymlinks) {
|
||||||
|
common.printSkipMessage('symlink test (no privs)');
|
||||||
|
return cb();
|
||||||
|
}
|
||||||
|
const tmpdir = require('../common/tmpdir');
|
||||||
|
tmpdir.refresh();
|
||||||
|
fs.mkdirSync(tmp('a'), 0o755);
|
||||||
|
fs.mkdirSync(tmp('a/b'), 0o755);
|
||||||
|
fs.symlinkSync('..', tmp('a/d'), 'dir');
|
||||||
|
unlink.push(tmp('a/d'));
|
||||||
|
fs.symlinkSync('..', tmp('a/b/e'), 'dir');
|
||||||
|
unlink.push(tmp('a/b/e'));
|
||||||
|
|
||||||
|
const abedabed = tmp('abedabed'.split('').join('/'));
|
||||||
|
const abedabed_real = tmp('');
|
||||||
|
|
||||||
|
const abedabeda = tmp('abedabeda'.split('').join('/'));
|
||||||
|
const abedabeda_real = tmp('a');
|
||||||
|
|
||||||
|
assertEqualPath(realpathSync(abedabeda), abedabeda_real);
|
||||||
|
assertEqualPath(realpathSync(abedabed), abedabed_real);
|
||||||
|
|
||||||
|
realpath(abedabeda, null, function(er, real) {
|
||||||
|
assert.ifError(er);
|
||||||
|
assertEqualPath(abedabeda_real, real);
|
||||||
|
realpath(abedabed, null, function(er, real) {
|
||||||
|
assert.ifError(er);
|
||||||
|
assertEqualPath(abedabed_real, real);
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Absolute symlinks with children.
|
// Absolute symlinks with children.
|
||||||
// .
|
// .
|
||||||
// `-- a/
|
// `-- a/
|
||||||
@ -474,10 +525,19 @@ function test_root(realpath, realpathSync, cb) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_root_with_null_options(realpath, realpathSync, cb) {
|
||||||
|
realpath('/', null, function(err, result) {
|
||||||
|
assert.ifError(err);
|
||||||
|
assertEqualPath(root, result);
|
||||||
|
cb();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
const tests = [
|
const tests = [
|
||||||
test_simple_error_callback,
|
test_simple_error_callback,
|
||||||
|
test_simple_error_cb_with_null_options,
|
||||||
test_simple_relative_symlink,
|
test_simple_relative_symlink,
|
||||||
test_simple_absolute_symlink,
|
test_simple_absolute_symlink,
|
||||||
test_deep_relative_file_symlink,
|
test_deep_relative_file_symlink,
|
||||||
@ -491,7 +551,9 @@ const tests = [
|
|||||||
test_upone_actual,
|
test_upone_actual,
|
||||||
test_abs_with_kids,
|
test_abs_with_kids,
|
||||||
test_up_multiple,
|
test_up_multiple,
|
||||||
|
test_up_multiple_with_null_options,
|
||||||
test_root,
|
test_root,
|
||||||
|
test_root_with_null_options
|
||||||
];
|
];
|
||||||
const numtests = tests.length;
|
const numtests = tests.length;
|
||||||
let testsRun = 0;
|
let testsRun = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user