Skip to content

Commit

Permalink
fs: use validateBoolean() in rm/rmdir validation
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored and MylesBorins committed Oct 14, 2020
1 parent 2992d0b commit 937fa5d
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
const { once } = require('internal/util');
const { toPathIfFileURL } = require('internal/url');
const {
validateBoolean,
validateInt32,
validateUint32
} = require('internal/validators');
Expand Down Expand Up @@ -674,15 +675,11 @@ const defaultRmdirOptions = {
const validateRmOptions = hideStackFrames((path, options, callback) => {
try {
options = validateRmdirOptions(options, defaultRmOptions);
validateBoolean(options.force, 'force');
} catch (err) {
return callback(err);
}

if (typeof options.force !== 'boolean')
return callback(
new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force)
);

lazyLoadFs().stat(path, (err, stats) => {
if (err) {
if (options.force && err.code === 'ENOENT') {
Expand All @@ -706,9 +703,7 @@ const validateRmOptions = hideStackFrames((path, options, callback) => {

const validateRmOptionsSync = hideStackFrames((path, options) => {
options = validateRmdirOptions(options, defaultRmOptions);

if (typeof options.force !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('force', 'boolean', options.force);
validateBoolean(options.force, 'force');

try {
const stats = lazyLoadFs().statSync(path);
Expand Down Expand Up @@ -742,9 +737,7 @@ const validateRmdirOptions = hideStackFrames(

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

if (typeof options.recursive !== 'boolean')
throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', options.recursive);

validateBoolean(options.recursive, 'recursive');
validateInt32(options.retryDelay, 'retryDelay', 0);
validateUint32(options.maxRetries, 'maxRetries');

Expand Down

0 comments on commit 937fa5d

Please sign in to comment.