-
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
fs readdir with buffer and file types problem #33348
Comments
This seems like a real bug, although it would be helpful to know what kind of directory entries there are in your directory since that will determine whether an error occurs or not. |
Sorry. |
Well, as I mentioned, it seems like a real bug for sure – but it would have been nice to have a reproduction available as a basis for a regression test. 👍 Basically, the issue is that this line: Line 188 in 8a6fab0
uses @vasyanewlifehere If you like, you are welcome to work on a PR? |
I could help with this issue. (UPD): will start working on it tommorow if there will be no answer from @vasyanewlifehere @vasyanewlifehere are you planning to work on PR? |
The following lines of code work if a dirent type is UV_DIRENT_UNKNOWN (which is crossplatform equivalent of DT_UNKNOWN). Line 188 in 8a6fab0
Line 217 in 8a6fab0
As to create a reproduction we need to force OS to return DT_UNKNOWN. I spent an hour on researching, and still don't know how to achive this on macOS.
The paragraph above is from this manpage. It got me thinking, that for reporoducing the bug on CI we will need to mount such a FS that will cause OS to return UV_DIRENT_UNKNOWN. Alternatively, according to this and that, we could find such a system where DT_UNKNOWN if undefined, so libuv will always return UV_DIRENT_UNKNOWN All that sounds really tough). @addaleax Are there other ways to force OS to return DT_UNKNOWN? Instead of having a reproduction, we could create unit tests for In code it will look something like
Tests
UPD: I created a reproduction on macOS. I definetely won't work on Windows. The test doesn't fail on Ubuntu.
@addaleax will it be OK if add unit tests only? |
@addaleax Can we assume that name and path args are correct and buffers are in 'utf-8' when we get
If not, it seems that we need to implement something similar to path.join for buffers.
Considereing the fact that a buffer may contain data in different encodings, the algorythm will be quite complex. Also, it seems to me that we can't stringify buffers and use path.join since we don't know a Buffer's encoding. |
I'd like to work on this issue. Has it been fixed? |
@shackjjj Thanks for the ping – no, unfortunately we can’t assume that |
Refs nodejs#33348 Co-authored-by: James M Snell <jasnell@gmail.com>
What steps will reproduce the bug?
reading directory with files names using buffer as path does not work.
It works correct in version 12.14.0 but after upgrade it stopped to work.
using it without files types works:
// fs.readdir( Buffer.from( "."),{withFileTypes:false,encoding:"buffer"},(e,d)=>console.log("dir",d));
How often does it reproduce? Is there a required condition?
every time
What is the expected behavior?
get directory entries with file types i.e. array of Dirent objects
What do you see instead?
error message:
Additional information
This bug is degradation because it doesn't exists in version 12.14.0 and present in versions 12.16.1 and 12.16.3 at least.
I use buffer instead of string because working with my old archives with non utf-8 names.
The text was updated successfully, but these errors were encountered: