Skip to content

Commit 937fa5d

Browse files
cjihrigMylesBorins
authored andcommitted
fs: use validateBoolean() in rm/rmdir validation
PR-URL: #35565 Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Denys Otrishko <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Masashi Hirano <[email protected]>
1 parent 2992d0b commit 937fa5d

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

lib/internal/fs/utils.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const {
3737
const { once } = require('internal/util');
3838
const { toPathIfFileURL } = require('internal/url');
3939
const {
40+
validateBoolean,
4041
validateInt32,
4142
validateUint32
4243
} = require('internal/validators');
@@ -674,15 +675,11 @@ const defaultRmdirOptions = {
674675
const validateRmOptions = hideStackFrames((path, options, callback) => {
675676
try {
676677
options = validateRmdirOptions(options, defaultRmOptions);
678+
validateBoolean(options.force, 'force');
677679
} catch (err) {
678680
return callback(err);
679681
}
680682

681-
if (typeof options.force !== 'boolean')
682-
return callback(
683-
new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force)
684-
);
685-
686683
lazyLoadFs().stat(path, (err, stats) => {
687684
if (err) {
688685
if (options.force && err.code === 'ENOENT') {
@@ -706,9 +703,7 @@ const validateRmOptions = hideStackFrames((path, options, callback) => {
706703

707704
const validateRmOptionsSync = hideStackFrames((path, options) => {
708705
options = validateRmdirOptions(options, defaultRmOptions);
709-
710-
if (typeof options.force !== 'boolean')
711-
throw new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force);
706+
validateBoolean(options.force, 'force');
712707

713708
try {
714709
const stats = lazyLoadFs().statSync(path);
@@ -742,9 +737,7 @@ const validateRmdirOptions = hideStackFrames(
742737

743738
options = { ...defaults, ...options };
744739

745-
if (typeof options.recursive !== 'boolean')
746-
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', options.recursive);
747-
740+
validateBoolean(options.recursive, 'recursive');
748741
validateInt32(options.retryDelay, 'retryDelay', 0);
749742
validateUint32(options.maxRetries, 'maxRetries');
750743

0 commit comments

Comments
 (0)