-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: avoid excluding symlinks in recursive fs.readdir with filetypes #55714
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
|
Please add a test; otherwise lgtm |
Will do |
0330a1d
to
10a71b9
Compare
@Ethan-Arrowood there we go! |
fs.readdirSync(a, { withFileTypes: true }).length, | ||
fs.readdirSync(a, { withFileTypes: false }).length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you not missing the recursive: true
option here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The directory you are creating here would look like:
|- a/
| |- file
| | b -> a/
And so I would expect readdirSync('a')
to return only 2 items, 'file'
and 'b'
.
When recursive: true
is enabled, what should happen? Would it be infinite?
That infinite behavior is potentially a separate issue.
Can you simplify the link here to maybe do something like:
|- x/
| |- 1
| |- 2
|- a/
| |- 1
| | b -> x/
And then assert that readdir('a', { recursive: true })
results in 4 entries?
'a/1', 'a/b', 'a/b/1', 'a/b/2'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Subsequently, it would be great to verify that such a test case currently fails on main
, but passes with your changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this is main
./node --inspect test/parallel/test-fs-readdir-types-symlinks.js
Debugger listening on ws://127.0.0.1:9229/8079dfce-ab06-46ca-b559-6dc4268378a4
For help, see: https://nodejs.org/en/docs/inspector
[
Dirent {
name: '1',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
[Symbol(type)]: 1
},
Dirent {
name: 'c',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
[Symbol(type)]: 3
}
]
[ '1', 'c', 'c/1', 'c/2' ]
node:assert:90
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
2 !== 4
And this is w/ this patch
./node --inspect test/parallel/test-fs-readdir-types-symlinks.js
Debugger listening on ws://127.0.0.1:9229/a2e2b4d3-6427-4488-858d-0cda545665ff
For help, see: https://nodejs.org/en/docs/inspector
[
Dirent {
name: '1',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
[Symbol(type)]: 1
},
Dirent {
name: 'c',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b',
[Symbol(type)]: 3
},
Dirent {
name: '1',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b/c',
[Symbol(type)]: 1
},
Dirent {
name: '2',
parentPath: '/Users/juanjose/GitHub/node/test/.tmp.0/b/c',
[Symbol(type)]: 1
}
]
[ '1', 'c', 'c/1', 'c/2' ]
Fixes: nodejs#52663 Signed-off-by: Juan José Arboleda <[email protected]>
10a71b9
to
a8a6aa0
Compare
@Ethan-Arrowood you were right, I've addressed your suggestions and tested the thing w/ main branch build. |
Fixes: #52663