Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: small rmdir() and validateRmOptions() cleanup #35567

Merged
merged 2 commits into from Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/fs.js
Expand Up @@ -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);
Expand Down
8 changes: 2 additions & 6 deletions lib/internal/fs/utils.js
Expand Up @@ -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',
Expand Down