Skip to content

Commit

Permalink
test: added a test
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 13, 2020
1 parent 3dfc53f commit 3ef437b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/internal/fs/rimraf.js
Expand Up @@ -12,6 +12,7 @@ const {
} = primordials;

const { Buffer } = require('buffer');
const fs = require('fs');
const {
chmod,
chmodSync,
Expand All @@ -25,7 +26,7 @@ const {
statSync,
unlink,
unlinkSync
} = require('fs');
} = fs;
const { sep } = require('path');
const { setTimeout } = require('timers');
const { sleep } = require('internal/util');
Expand Down Expand Up @@ -249,7 +250,7 @@ function _rmdirSync(path, options, originalErr) {

for (let i = 1; i <= tries; i++) {
try {
return rmdirSync(path);
return fs.rmdirSync(path);
} catch (err) {
// Only sleep if this is not the last try, and the delay is greater
// than zero, and an error was encountered that warrants a retry.
Expand Down
25 changes: 25 additions & 0 deletions test/parallel/test-fs-rmdir-recursive.js
Expand Up @@ -211,3 +211,28 @@ function removeAsync(dir) {
message: /^The value of "options\.maxRetries" is out of range\./
});
}

// It should not pass recursive option to rmdirSync, when called from
// rimraf (see: #35566)
{
// Make a non-empty directory:
const original = fs.rmdirSync;
const dir = `${nextDirPath()}/foo/bar`;
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(`${dir}/foo.txt`, 'hello world', 'utf8');

// When called the second time from rimraf, the recursive option should
// not be set for rmdirSync:
let callCount = 0;
let rmdirSyncOptionsFromRimraf;
fs.rmdirSync = (path, options) => {
if (callCount > 0) {
rmdirSyncOptionsFromRimraf = { ...options };
}
callCount++;
return original(path, options);
};
fs.rmdirSync(dir, { recursive: true });
fs.rmdirSync = original;
assert.strictEqual(rmdirSyncOptionsFromRimraf.recursive, undefined);
}

0 comments on commit 3ef437b

Please sign in to comment.