From f0c55e206d69e24d9299b73773ee822ac0423973 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli <yagiz@nizipli.com> 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 <livia@cirno.name> Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> --- 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); }); - }); + } }); }