From 741004a3b88a4ce8563a1b46e429ae332f2f8e1a 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 7269c0fc3fd658..181150f2b7e492 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -7,7 +7,6 @@ 'use strict'; const { - ArrayPrototypeForEach, Promise, SafeSet, } = primordials; @@ -132,8 +131,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) @@ -148,7 +149,7 @@ function _rmchildren(path, options, callback) { if (numFiles === 0) rmdir(path, callback); }); - }); + } }); }