From 1d5b835f551fb6dac90806392e357459aac0ea8f Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 9 Sep 2024 22:32:57 -0400 Subject: [PATCH] fs: refactor rimraf to avoid using primordials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/54834 Reviewed-By: LiviaMedeiros Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell Reviewed-By: Moshe Atlow Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca --- lib/internal/fs/rimraf.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 877f238011cb95..d5732ef3dbd82f 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -140,8 +140,10 @@ function _rmchildren(path, options, callback) { let done = false; - ArrayPrototypeForEach(files, (child) => { - const childPath = Buffer.concat([pathBuf, separator, child]); + const childPathPrefix = Buffer.concat([pathBuf, separator]); + + for (let i = 0; i < files.length; i++) { + const childPath = Buffer.concat([childPathPrefix, files[i]]); rimraf(childPath, options, (err) => { if (done) @@ -156,7 +158,7 @@ function _rmchildren(path, options, callback) { if (numFiles === 0) rmdir(path, callback); }); - }); + } }); }