Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 76affb6

Browse filesBrowse files
cjihrigtargos
authored andcommitted
fs: only operate on buffers in rimraf
PR-URL: #30569 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent ffc910f commit 76affb6
Copy full SHA for 76affb6

File tree

Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed
Open diff view settings
Collapse file

‎lib/internal/fs/rimraf.js‎

Copy file name to clipboardExpand all lines: lib/internal/fs/rimraf.js
+16-5Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111
Set,
1212
} = primordials;
1313

14+
const { Buffer } = require('buffer');
1415
const {
1516
chmod,
1617
chmodSync,
@@ -25,7 +26,7 @@ const {
2526
unlink,
2627
unlinkSync
2728
} = require('fs');
28-
const { join } = require('path');
29+
const { sep } = require('path');
2930
const { setTimeout } = require('timers');
3031
const { sleep } = require('internal/util');
3132
const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']);
@@ -34,6 +35,8 @@ const retryErrorCodes = new Set(
3435
const isWindows = process.platform === 'win32';
3536
const epermHandler = isWindows ? fixWinEPERM : _rmdir;
3637
const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync;
38+
const readdirEncoding = 'buffer';
39+
const separator = Buffer.from(sep);
3740

3841

3942
function rimraf(path, options, callback) {
@@ -122,7 +125,9 @@ function _rmdir(path, options, originalErr, callback) {
122125

123126

124127
function _rmchildren(path, options, callback) {
125-
readdir(path, (err, files) => {
128+
const pathBuf = Buffer.from(path);
129+
130+
readdir(pathBuf, readdirEncoding, (err, files) => {
126131
if (err)
127132
return callback(err);
128133

@@ -134,7 +139,9 @@ function _rmchildren(path, options, callback) {
134139
let done = false;
135140

136141
files.forEach((child) => {
137-
rimraf(join(path, child), options, (err) => {
142+
const childPath = Buffer.concat([pathBuf, separator, child]);
143+
144+
rimraf(childPath, options, (err) => {
138145
if (done)
139146
return;
140147

@@ -211,8 +218,12 @@ function _rmdirSync(path, options, originalErr) {
211218
// original removal. Windows has a habit of not closing handles promptly
212219
// when files are deleted, resulting in spurious ENOTEMPTY failures. Work
213220
// around that issue by retrying on Windows.
214-
readdirSync(path).forEach((child) => {
215-
rimrafSync(join(path, child), options);
221+
const pathBuf = Buffer.from(path);
222+
223+
readdirSync(pathBuf, readdirEncoding).forEach((child) => {
224+
const childPath = Buffer.concat([pathBuf, separator, child]);
225+
226+
rimrafSync(childPath, options);
216227
});
217228

218229
const tries = options.maxRetries + 1;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.