mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
fs: fix bufferSize option for opendir recursive
The bufferSize option was not respected in recursive mode. This PR implements a naive solution to fix this issue until a better implementation can be designed. Fixes: https://github.com/nodejs/node/issues/48820 PR-URL: https://github.com/nodejs/node/pull/55744 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
37c941be05
commit
e0ef622c54
@ -164,12 +164,16 @@ class Dir {
|
||||
return;
|
||||
}
|
||||
|
||||
const result = handle.read(
|
||||
// Fully read the directory and buffer the entries.
|
||||
// This is a naive solution and for very large sub-directories
|
||||
// it can even block the event loop. Essentially, `bufferSize` is
|
||||
// not respected for recursive mode. This is a known limitation.
|
||||
// Issue to fix: https://github.com/nodejs/node/issues/55764
|
||||
let result;
|
||||
while ((result = handle.read(
|
||||
this.#options.encoding,
|
||||
this.#options.bufferSize,
|
||||
);
|
||||
|
||||
if (result) {
|
||||
))) {
|
||||
this.processReadResult(path, result);
|
||||
}
|
||||
|
||||
|
@ -132,6 +132,7 @@ function getDirentPath(dirent) {
|
||||
}
|
||||
|
||||
function assertDirents(dirents) {
|
||||
assert.strictEqual(dirents.length, expected.length);
|
||||
dirents.sort((a, b) => (getDirentPath(a) < getDirentPath(b) ? -1 : 1));
|
||||
assert.deepStrictEqual(
|
||||
dirents.map((dirent) => {
|
||||
@ -221,3 +222,21 @@ function processDirCb(dir, cb) {
|
||||
|
||||
test().then(common.mustCall());
|
||||
}
|
||||
|
||||
// Issue https://github.com/nodejs/node/issues/48820 highlights that
|
||||
// opendir recursive does not properly handle the buffer size option.
|
||||
// This test asserts that the buffer size option is respected.
|
||||
{
|
||||
const dir = fs.opendirSync(testDir, { bufferSize: 1, recursive: true });
|
||||
processDirSync(dir);
|
||||
dir.closeSync();
|
||||
}
|
||||
|
||||
{
|
||||
fs.opendir(testDir, { recursive: true, bufferSize: 1 }, common.mustSucceed((dir) => {
|
||||
processDirCb(dir, common.mustSucceed((dirents) => {
|
||||
assertDirents(dirents);
|
||||
dir.close(common.mustSucceed());
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user