diff options
author | cjihrig <cjihrig@gmail.com> | 2019-11-21 00:06:08 +0300 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2019-12-10 17:22:02 +0300 |
commit | 152014a8933e3b55bdaa24158ec12582ae0ca8f9 (patch) | |
tree | f90ba26ad2a4b26978d86a72c5df1e9c17ba25c3 /lib/internal/fs | |
parent | 7629fb25f2c97de9926f71724072ad2b2af27c85 (diff) |
fs: only operate on buffers in rimraf
PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib/internal/fs')
-rw-r--r-- | lib/internal/fs/rimraf.js | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/lib/internal/fs/rimraf.js b/lib/internal/fs/rimraf.js index 6d6b19efcc9..38bbb66a47d 100644 --- a/lib/internal/fs/rimraf.js +++ b/lib/internal/fs/rimraf.js @@ -5,6 +5,7 @@ // - Bring your own custom fs module is not currently supported. // - Some basic code cleanup. 'use strict'; +const { Buffer } = require('buffer'); const { chmod, chmodSync, @@ -19,7 +20,7 @@ const { unlink, unlinkSync } = require('fs'); -const { join } = require('path'); +const { sep } = require('path'); const { setTimeout } = require('timers'); const { sleep } = require('internal/util'); const notEmptyErrorCodes = new Set(['ENOTEMPTY', 'EEXIST', 'EPERM']); @@ -28,6 +29,8 @@ const retryErrorCodes = new Set( const isWindows = process.platform === 'win32'; const epermHandler = isWindows ? fixWinEPERM : _rmdir; const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync; +const readdirEncoding = 'buffer'; +const separator = Buffer.from(sep); function rimraf(path, options, callback) { @@ -116,7 +119,9 @@ function _rmdir(path, options, originalErr, callback) { function _rmchildren(path, options, callback) { - readdir(path, (err, files) => { + const pathBuf = Buffer.from(path); + + readdir(pathBuf, readdirEncoding, (err, files) => { if (err) return callback(err); @@ -128,7 +133,9 @@ function _rmchildren(path, options, callback) { let done = false; files.forEach((child) => { - rimraf(join(path, child), options, (err) => { + const childPath = Buffer.concat([pathBuf, separator, child]); + + rimraf(childPath, options, (err) => { if (done) return; @@ -205,8 +212,12 @@ function _rmdirSync(path, options, originalErr) { // original removal. Windows has a habit of not closing handles promptly // when files are deleted, resulting in spurious ENOTEMPTY failures. Work // around that issue by retrying on Windows. - readdirSync(path).forEach((child) => { - rimrafSync(join(path, child), options); + const pathBuf = Buffer.from(path); + + readdirSync(pathBuf, readdirEncoding).forEach((child) => { + const childPath = Buffer.concat([pathBuf, separator, child]); + + rimrafSync(childPath, options); }); const tries = options.maxRetries + 1; |