mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
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:
1 parent
b5e25aa2ce
commit
91099658a6
2 files changed
+11
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user