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: nodejs#35565
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
  • Loading branch information
cjihrig authored and joesepi committed Oct 22, 2020
1 parent 0107e5c commit e5be99d
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 @@ -35,6 +35,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 e5be99d

Please sign in to comment.