mirror of https://github.com/nodejs/node.git
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>pull/56243/head
parent
b5e25aa2ce
commit
91099658a6
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue