forked from nodejs/node
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: fix busy loop in recursive rm for windows
Fixes: nodejs#34580
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
require('../common'); | ||
|
||
// This test ensures that recursive rm throws EACCES instead of | ||
// going into a busy-loop for this scenario: | ||
// https://github.com/nodejs/node/issues/34580 | ||
|
||
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const { join } = require('path'); | ||
|
||
tmpdir.refresh(); | ||
|
||
function rmdirRecursiveSync() { | ||
const root = fs.mkdtempSync(tmpdir.path); | ||
|
||
const middle = join(root, 'middle'); | ||
fs.mkdirSync(middle); | ||
fs.mkdirSync(join(middle, 'leaf')); // Make `middle` non-empty | ||
fs.chmodSync(middle, 0); | ||
|
||
// Windows can EPERM on stat, which is called inside rmdirSync. | ||
let runTest = false; | ||
try { | ||
fs.statSync(middle); | ||
runTest = true; | ||
} catch (err) { | ||
assert.strictEqual(err.code, 'EPERM'); | ||
} finally { | ||
try { | ||
if (runTest) { | ||
assert.throws(() => { | ||
fs.rmSync(root, { recursive: true }); | ||
}, /EACCES/); | ||
} | ||
} finally { | ||
fs.chmodSync(middle, 0o777); | ||
fs.rmdirSync(root, { recursive: true }); | ||
} | ||
} | ||
} | ||
|
||
rmdirRecursiveSync(); |