Skip to content

fs: remove recursive option from rmdir #57784

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3026,6 +3026,9 @@ The [`crypto.Certificate()` constructor][] is deprecated. Use

<!-- YAML
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57784
description: End-of-Life.
- version: v16.0.0
pr-url: https://github.com/nodejs/node/pull/37302
description: Runtime deprecation.
Expand All @@ -3037,10 +3040,10 @@ changes:
description: Documentation-only deprecation.
-->

Type: Runtime
Type: End-of-Life

In future versions of Node.js, `recursive` option will be ignored for
`fs.rmdir`, `fs.rmdirSync`, and `fs.promises.rmdir`.
`recursive` option is ignored for `fs.rmdir`, `fs.rmdirSync`,
and `fs.promises.rmdir`.

Use `fs.rm(path, { recursive: true, force: true })`,
`fs.rmSync(path, { recursive: true, force: true })` or
Expand Down
18 changes: 9 additions & 9 deletions doc/api/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ Renames `oldPath` to `newPath`.
<!-- YAML
added: v10.0.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57784
description: The `recursive` option is removed, use `fsPromises.rm` instead.
- version: v16.0.0
pr-url: https://github.com/nodejs/node/pull/37216
description: "Using `fsPromises.rmdir(path, { recursive: true })` on a `path`
Expand Down Expand Up @@ -1614,9 +1617,6 @@ changes:
backoff wait of `retryDelay` milliseconds longer on each try. This option
represents the number of retries. This option is ignored if the `recursive`
option is not `true`. **Default:** `0`.
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
recursive mode, operations are retried on failure. **Default:** `false`.
**Deprecated.**
* `retryDelay` {integer} The amount of time in milliseconds to wait between
retries. This option is ignored if the `recursive` option is not `true`.
**Default:** `100`.
Expand Down Expand Up @@ -4233,6 +4233,9 @@ rename('oldFile.txt', 'newFile.txt', (err) => {
<!-- YAML
added: v0.0.2
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57784
description: The `recursive` option is removed, use `fs.rm` instead.
- version: v18.0.0
pr-url: https://github.com/nodejs/node/pull/41678
description: Passing an invalid callback to the `callback` argument
Expand Down Expand Up @@ -4289,9 +4292,6 @@ changes:
backoff wait of `retryDelay` milliseconds longer on each try. This option
represents the number of retries. This option is ignored if the `recursive`
option is not `true`. **Default:** `0`.
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
recursive mode, operations are retried on failure. **Default:** `false`.
**Deprecated.**
* `retryDelay` {integer} The amount of time in milliseconds to wait between
retries. This option is ignored if the `recursive` option is not `true`.
**Default:** `100`.
Expand Down Expand Up @@ -6209,6 +6209,9 @@ See the POSIX rename(2) documentation for more details.
<!-- YAML
added: v0.1.21
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/57784
description: The `recursive` option is removed, use `fs.rmSync` instead.
- version: v16.0.0
pr-url: https://github.com/nodejs/node/pull/37216
description: "Using `fs.rmdirSync(path, { recursive: true })` on a `path`
Expand Down Expand Up @@ -6252,9 +6255,6 @@ changes:
backoff wait of `retryDelay` milliseconds longer on each try. This option
represents the number of retries. This option is ignored if the `recursive`
option is not `true`. **Default:** `0`.
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
recursive mode, operations are retried on failure. **Default:** `false`.
**Deprecated.**
* `retryDelay` {integer} The amount of time in milliseconds to wait between
retries. This option is ignored if the `recursive` option is not `true`.
**Default:** `100`.
Expand Down
44 changes: 5 additions & 39 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const {
},
copyObject,
Dirent,
emitRecursiveRmdirWarning,
getDirent,
getDirents,
getOptions,
Expand Down Expand Up @@ -1111,7 +1110,6 @@ function lazyLoadRimraf() {
* @param {string | Buffer | URL} path
* @param {{
* maxRetries?: number;
* recursive?: boolean;
* retryDelay?: number;
* }} [options]
* @param {(err?: Error) => any} callback
Expand All @@ -1125,57 +1123,25 @@ function rmdir(path, options, callback) {

callback = makeCallback(callback);
path = getValidatedPath(path);
validateRmdirOptions(options);

if (options?.recursive) {
emitRecursiveRmdirWarning();
validateRmOptions(
path,
{ ...options, force: false },
true,
(err, options) => {
if (err === false) {
const req = new FSReqCallback();
req.oncomplete = callback;
binding.rmdir(path, req);
return;
}
if (err) {
return callback(err);
}

lazyLoadRimraf();
rimraf(path, options, callback);
});
} else {
validateRmdirOptions(options);
const req = new FSReqCallback();
req.oncomplete = callback;
binding.rmdir(path, req);
}
const req = new FSReqCallback();
req.oncomplete = callback;
binding.rmdir(path, req);
}

/**
* Synchronously removes a directory.
* @param {string | Buffer | URL} path
* @param {{
* maxRetries?: number;
* recursive?: boolean;
* retryDelay?: number;
* }} [options]
* @returns {void}
*/
function rmdirSync(path, options) {
path = getValidatedPath(path);

if (options?.recursive) {
emitRecursiveRmdirWarning();
options = validateRmOptionsSync(path, { ...options, force: false }, true);
if (options !== false) {
return binding.rmSync(path, options.maxRetries, options.recursive, options.retryDelay);
}
} else {
validateRmdirOptions(options);
}
validateRmdirOptions(options);

binding.rmdir(path);
}
Expand Down
9 changes: 0 additions & 9 deletions lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const {
kWriteFileMaxChunkSize,
},
copyObject,
emitRecursiveRmdirWarning,
getDirents,
getOptions,
getStatFsFromBinding,
Expand Down Expand Up @@ -808,14 +807,6 @@ async function rmdir(path, options) {
path = getValidatedPath(path);
options = validateRmdirOptions(options);

if (options.recursive) {
emitRecursiveRmdirWarning();
const stats = await stat(path);
if (stats.isDirectory()) {
return lazyRimRaf()(path, options);
}
}

return await PromisePrototypeThen(
binding.rmdir(path, kUsePromises),
undefined,
Expand Down
21 changes: 1 addition & 20 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,6 @@ const defaultRmOptions = {
const defaultRmdirOptions = {
retryDelay: 100,
maxRetries: 0,
recursive: false,
};

const validateCpOptions = hideStackFrames((options) => {
Expand Down Expand Up @@ -839,6 +838,7 @@ const validateRmOptions = hideStackFrames((path, options, expectDir, cb) => {
const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => {
options = validateRmdirOptions.withoutStackTrace(options, defaultRmOptions);
validateBoolean.withoutStackTrace(options.force, 'options.force');
validateBoolean.withoutStackTrace(options.recursive, 'options.recursive');

if (!options.force || expectDir || !options.recursive) {
const isDirectory = lazyLoadFs()
Expand All @@ -862,23 +862,6 @@ const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => {
return options;
});

let recursiveRmdirWarned;
function emitRecursiveRmdirWarning() {
if (recursiveRmdirWarned === undefined) {
// TODO(joyeecheung): use getOptionValue('--no-deprecation') instead.
recursiveRmdirWarned = process.noDeprecation;
}
if (!recursiveRmdirWarned) {
process.emitWarning(
'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' +
'will be removed. Use fs.rm(path, { recursive: true }) instead',
'DeprecationWarning',
'DEP0147',
);
recursiveRmdirWarned = true;
}
}

const validateRmdirOptions = hideStackFrames(
(options, defaults = defaultRmdirOptions) => {
if (options === undefined)
Expand All @@ -887,7 +870,6 @@ const validateRmdirOptions = hideStackFrames(

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

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

Expand Down Expand Up @@ -950,7 +932,6 @@ module.exports = {
copyObject,
Dirent,
DirentFromStats,
emitRecursiveRmdirWarning,
getDirent,
getDirents,
getOptions,
Expand Down
22 changes: 0 additions & 22 deletions test/parallel/test-fs-rmdir-recursive-sync-warns-not-found.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/parallel/test-fs-rmdir-recursive-sync-warns-on-file.js

This file was deleted.

21 changes: 0 additions & 21 deletions test/parallel/test-fs-rmdir-recursive-warns-not-found.js

This file was deleted.

21 changes: 0 additions & 21 deletions test/parallel/test-fs-rmdir-recursive-warns-on-file.js

This file was deleted.

Loading
Loading