Skip to content

Commit 6b821a9

Browse files
committed
fixup! fs: remove permissive rmdir recursive
1 parent a896cbe commit 6b821a9

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

doc/api/deprecations.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -2665,20 +2665,22 @@ The [`crypto.Certificate()` constructor][] is deprecated. Use
26652665
changes:
26662666
- version: REPLACEME
26672667
pr-url: https://github.com/nodejs/node/pull/37216
2668-
description: End-of-Life.
2668+
description: Runtime deprecation.
26692669
- version: v15.0.0
26702670
pr-url: https://github.com/nodejs/node/pull/35562
2671-
description: Runtime deprecation.
2671+
description: Runtime deprecation for permissive behavior.
26722672
- version: v14.14.0
26732673
pr-url: https://github.com/nodejs/node/pull/35579
26742674
description: Documentation-only deprecation.
26752675
-->
26762676

2677-
Type: End-of-Life
2677+
Type: Runtime
26782678

26792679
`fs.rmdir(path, { recursive: true })`, `fs.rmdirSync(path, { recursive:true })`
2680-
and `fs.promises.rmdir(path, { recursive:true })` will throw
2681-
if `path` does not exist or is a file.
2680+
and `fs.promises.rmdir(path, { recursive:true })` throws if `path` does not
2681+
exist or is a file, and emits a warning if path is a directory. In future
2682+
versions of Node.js, `recursive` option will be ignored.
2683+
26822684
Use `fs.rm(path, { recursive: true, force: true })`,
26832685
`fs.rmSync(path, { recursive: true, force: true })` or
26842686
`fs.promises.rm(path, { recursive: true, force: true })` instead.

doc/api/fs.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -3629,6 +3629,7 @@ changes:
36293629
option is not `true`. **Default:** `0`.
36303630
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
36313631
recursive mode, operations are retried on failure. **Default:** `false`.
3632+
**Deprecated**.
36323633
* `retryDelay` {integer} The amount of time in milliseconds to wait between
36333634
retries. This option is ignored if the `recursive` option is not `true`.
36343635
**Default:** `100`.
@@ -3686,7 +3687,7 @@ changes:
36863687
option is not `true`. **Default:** `0`.
36873688
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
36883689
recursive mode, errors are not reported if `path` does not exist, and
3689-
operations are retried on failure. **Default:** `false`.
3690+
operations are retried on failure. **Default:** `false`. **Deprecated**.
36903691
* `retryDelay` {integer} The amount of time in milliseconds to wait between
36913692
retries. This option is ignored if the `recursive` option is not `true`.
36923693
**Default:** `100`.
@@ -5711,6 +5712,7 @@ changes:
57115712
option is not `true`. **Default:** `0`.
57125713
* `recursive` {boolean} If `true`, perform a recursive directory removal. In
57135714
recursive mode, operations are retried on failure. **Default:** `false`.
5715+
**Deprecated**.
57145716
* `retryDelay` {integer} The amount of time in milliseconds to wait between
57155717
retries. This option is ignored if the `recursive` option is not `true`.
57165718
**Default:** `100`.

lib/internal/fs/promises.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ const {
4141
ERR_INVALID_ARG_VALUE,
4242
ERR_METHOD_NOT_IMPLEMENTED,
4343
} = codes;
44-
const { isArrayBufferView } = require('internal/util/types');
44+
const {
45+
isArrayBufferView,
46+
emitRecursiveRmdirWarning,
47+
} = require('internal/util/types');
4548
const { rimrafPromises } = require('internal/fs/rimraf');
4649
const {
4750
copyObject,
@@ -488,6 +491,7 @@ async function rmdir(path, options) {
488491
options = validateRmdirOptions(options);
489492

490493
if (options.recursive) {
494+
emitRecursiveRmdirWarning();
491495
const stats = await stat(path);
492496
if (stats.isDirectory()) {
493497
return rimrafPromises(path, options);

lib/internal/fs/utils.js

+18
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,19 @@ const validateRmOptionsSync = hideStackFrames((path, options, expectDir) => {
741741
return options;
742742
});
743743

744+
let recursiveRmdirWarned = process.noDeprecation;
745+
function emitRecursiveRmdirWarning() {
746+
if (!recursiveRmdirWarned) {
747+
process.emitWarning(
748+
'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' +
749+
'will be removed. Use fs.rm(path, { recursive: true }) instead',
750+
'DeprecationWarning',
751+
'DEP0147'
752+
);
753+
recursiveRmdirWarned = true;
754+
}
755+
}
756+
744757
const validateRmdirOptions = hideStackFrames(
745758
(options, defaults = defaultRmdirOptions) => {
746759
if (options === undefined)
@@ -753,6 +766,10 @@ const validateRmdirOptions = hideStackFrames(
753766
validateInt32(options.retryDelay, 'options.retryDelay', 0);
754767
validateUint32(options.maxRetries, 'options.maxRetries');
755768

769+
if (options.recursive) {
770+
emitRecursiveRmdirWarning();
771+
}
772+
756773
return options;
757774
});
758775

@@ -822,6 +839,7 @@ module.exports = {
822839
BigIntStats, // for testing
823840
copyObject,
824841
Dirent,
842+
emitRecursiveRmdirWarning,
825843
getDirent,
826844
getDirents,
827845
getOptions,

test/parallel/test-fs-rmdir-recursive.js

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const fs = require('fs');
77
const path = require('path');
88
const { validateRmdirOptions } = require('internal/fs/utils');
99

10+
common.expectWarning(
11+
'In future versions of Node.js, fs.rmdir(path, { recursive: true }) ' +
12+
'will be removed. Use fs.rm(path, { recursive: true }) instead',
13+
'DeprecationWarning',
14+
'DEP0147'
15+
);
16+
1017
tmpdir.refresh();
1118

1219
let count = 0;

0 commit comments

Comments
 (0)