fs: make mutating options in Callback readdir() not affect results

PR-URL: https://github.com/nodejs/node/pull/56057
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
LiviaMedeiros authored and Node.js GitHub Bot committed 2024-12-12 21:25:53 +00:00
1 parent b5e25aa2ce
commit 91099658a6
2 files changed
+11

No files matched your search

+3
View File
@@ -1531,6 +1531,9 @@ function readdir(path, options, callback) {
}
if (options.recursive) {
// Make shallow copy to prevent mutating options from affecting results
options = copyObject(options);
readdirRecursive(path, options, callback);
return;
}
+8
View File
@@ -86,6 +86,14 @@ fs.readdir(readdirDir, {
assertDirents(await direntsPromise);
})().then(common.mustCall());
{
const options = { recursive: true, withFileTypes: true };
fs.readdir(readdirDir, options, common.mustSucceed((dirents) => {
assertDirents(dirents);
}));
options.withFileTypes = false;
}
// Check for correct types when the binding returns unknowns
const UNKNOWN = constants.UV_DIRENT_UNKNOWN;
const oldReaddir = binding.readdir;