From 3ef437bf994cbdc24a0a3379241eae8cb48b8342 Mon Sep 17 00:00:00 2001 From: bcoe Date: Sun, 11 Oct 2020 11:45:59 -0700 Subject: [PATCH] test: added a test --- lib/internal/fs/rimraf.js | 5 +++-- test/parallel/test-fs-rmdir-recursive.js | 25 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index b8eade61cf9bea..e67b14a418c884 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -12,6 +12,7 @@ const { } = primordials; const { Buffer } = require('buffer'); +const fs = require('fs'); const { chmod, chmodSync, @@ -25,7 +26,7 @@ const { statSync, unlink, unlinkSync -} = require('fs'); +} = fs; const { sep } = require('path'); const { setTimeout } = require('timers'); const { sleep } = require('internal/util'); @@ -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. diff --git a/test/parallel/test-fs-rmdir-recursive.js b/test/parallel/test-fs-rmdir-recursive.js index 1d2525a5ed6341..bbf89a3959e19d 100644 --- a/test/parallel/test-fs-rmdir-recursive.js +++ b/test/parallel/test-fs-rmdir-recursive.js @@ -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); +}