Skip to content

Commit a3c7f8e

Browse files
bcoeMylesBorins
authored andcommitted
fs: rimraf should not recurse on failure
PR-URL: #35566 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 41d7500 commit a3c7f8e

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

lib/internal/fs/rimraf.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
} = primordials;
1313

1414
const { Buffer } = require('buffer');
15+
const fs = require('fs');
1516
const {
1617
chmod,
1718
chmodSync,
@@ -25,7 +26,7 @@ const {
2526
statSync,
2627
unlink,
2728
unlinkSync
28-
} = require('fs');
29+
} = fs;
2930
const { sep } = require('path');
3031
const { setTimeout } = require('timers');
3132
const { sleep } = require('internal/util');
@@ -249,7 +250,7 @@ function _rmdirSync(path, options, originalErr) {
249250

250251
for (let i = 1; i <= tries; i++) {
251252
try {
252-
return rmdirSync(path, options);
253+
return fs.rmdirSync(path);
253254
} catch (err) {
254255
// Only sleep if this is not the last try, and the delay is greater
255256
// than zero, and an error was encountered that warrants a retry.

test/known_issues/known_issues.status

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
prefix known_issues
23

34
# If a known issue does not apply to a platform, list the test name in the
@@ -27,5 +28,3 @@ test-vm-timeout-escape-queuemicrotask: SKIP
2728
# The Raspberry Pis are too slow to run this test.
2829
# See https://github.com/nodejs/build/issues/2227#issuecomment-608334574
2930
test-crypto-authenticated-stream: SKIP
30-
# The bug being checked is that the test never exits.
31-
test-fs-open-no-close: TIMEOUT

test/known_issues/test-fs-open-no-close.js test/parallel/test-fs-open-no-close.js

-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
// Failing to close a file should not keep the event loop open.
55

66
const common = require('../common');
7-
8-
// This issue only shows up on Raspberry Pi devices in our CI. When this test is
9-
// moved out of known_issues, this check can be removed, as the test should pass
10-
// on all platforms at that point.
117
const assert = require('assert');
12-
if (process.arch !== 'arm' || process.config.variables.arm_version > 7) {
13-
assert.fail('This test is for Raspberry Pi devices in CI');
14-
}
158

169
const fs = require('fs');
1710

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

+25
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,28 @@ function removeAsync(dir) {
211211
message: /^The value of "options\.maxRetries" is out of range\./
212212
});
213213
}
214+
215+
// It should not pass recursive option to rmdirSync, when called from
216+
// rimraf (see: #35566)
217+
{
218+
// Make a non-empty directory:
219+
const original = fs.rmdirSync;
220+
const dir = `${nextDirPath()}/foo/bar`;
221+
fs.mkdirSync(dir, { recursive: true });
222+
fs.writeFileSync(`${dir}/foo.txt`, 'hello world', 'utf8');
223+
224+
// When called the second time from rimraf, the recursive option should
225+
// not be set for rmdirSync:
226+
let callCount = 0;
227+
let rmdirSyncOptionsFromRimraf;
228+
fs.rmdirSync = (path, options) => {
229+
if (callCount > 0) {
230+
rmdirSyncOptionsFromRimraf = { ...options };
231+
}
232+
callCount++;
233+
return original(path, options);
234+
};
235+
fs.rmdirSync(dir, { recursive: true });
236+
fs.rmdirSync = original;
237+
assert.strictEqual(rmdirSyncOptionsFromRimraf.recursive, undefined);
238+
}

0 commit comments

Comments
 (0)