diff --git a/lib/fs.js b/lib/fs.js index d07cefcaa9cb33..c570a8c9f4fc2e 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -859,20 +859,16 @@ function rmdir(path, options, callback) { path = pathModule.toNamespacedPath(getValidatedPath(path)); if (options && options.recursive) { - options = validateRmOptions( - path, - { ...options, force: true }, - (err, options) => { - if (err) { - return callback(err); - } - - lazyLoadRimraf(); - return rimraf(path, options, callback); - }); + validateRmOptions(path, { ...options, force: true }, (err, options) => { + if (err) { + return callback(err); + } + lazyLoadRimraf(); + return rimraf(path, options, callback); + }); } else { - options = validateRmdirOptions(options); + validateRmdirOptions(options); const req = new FSReqCallback(); req.oncomplete = callback; return binding.rmdir(path, req); diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index ff2033ed326455..658f764ee22864 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -684,17 +684,13 @@ const validateRmOptions = hideStackFrames((path, options, callback) => { ); lazyLoadFs().stat(path, (err, stats) => { - if (err && err.code === 'ENOENT') { - if (options.force) { + if (err) { + if (options.force && err.code === 'ENOENT') { return callback(null, options); } return callback(err, options); } - if (err) { - return callback(err); - } - if (stats.isDirectory() && !options.recursive) { return callback(new ERR_FS_EISDIR({ code: 'EISDIR',