-
Notifications
You must be signed in to change notification settings - Fork 654
fs: ifx uv_fs_readdir_next reported types #1421
Conversation
I think we can do better at checking if Relatedly, it seems like we should be reporting more than just I know that the windows implementation is slightly deficient in what it can report currently, but according to |
What glibc macro is that? I checked musl, but I may have missed it. I'll also check what BSDs do, just in case. |
To quote the die.net manpage
|
if (dent->d_type == UV__DT_DIR) | ||
ent->type = UV_DIRENT_DIR; | ||
else | ||
else if (dent->d_type == UV__DT_FILE) |
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.
After a second thought, I don't really enjoy this line. Could we do ifdef UV__DT_FILE
here?
It is very painful to polyfill this, if the most of the file types are unknowns. In fact, the most useful information is dir/not-dir here, and with your patch we are loosing it.
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.
Actually, I'd even try to polyfill it on solaris. @tjfontaine are there any way, except stat
to get what we need 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.
Let me check what we have on the libcs supporting dirent types. IMHO doing stat
is overkill. I'd rather say unknown since we don't actually know and let the user stat if he wants to.
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.
Ok...
So, about the Unix side: I checked a few libcs:
So, I'd say the base can be this:
Any implementation which support dirent types needs to have a DT_UNKNOWN one, so we can use that to detect support. Then, for each type we could do this:
and so on. Since those constants are always possitive, but our polyfills negative, we can have the if-else-if there just fine, and the last else would set the type to UV_DIRENT_UNKNOWN. Then we can use ifdef HAVE_DIRENT_TYPES to either do the checks or always use unknown (like this patch does). Thoughts? /cc @indutny @txdv (since you were also looking into this yesterday) |
Makes sense. |
I just added support for links on both Unix and Windows. This is the complete list of types:
So we are missing DT_FIFO, DT_SOCK, DT_CHR and DT_BLK on Unices (which support them). I guess we also want those, right? On Windows a thing can only be a folder, a file or a link, FWIW. |
Ok, that makes it all types. I used longer names, because unlike in the 80s, characters don't cost money. |
Posting this again. http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html http://msdn.microsoft.com/en-us/library/windows/desktop/gg258117(v=vs.85).aspx I thinks this is a good change, we should return as much information as possible. The other windows values though seem not to be very interesting. |
Yep, that's where I took the data from. |
Great @saghul, so all file types can be detected on Windows! |
Exactly, there is no match in the data we get in readdir / scandir. Also, being readonly or hidden is not really a file "type" it's more like an attribute of the file itself. Not sure if we can report more on I squashed the commits and force pushed. |
Support all possible types on Unix, and files, directories and links on Windows. Some systems (hello SunOS!) don't have the d_type field on struct dirent, so mark them as UV_DIRENT_UNKNOWN.
In windows you can get a lot of information about directory entries (see http://msdn.microsoft.com/en-us/library/windows/hardware/ff540303%28v=vs.85%29.aspx). But it's not possible to see symbolic links - they will be reported either as files or as directories. |
Contradicting myself:
Actually, on the cygwin mailing list, I read this:
|
@piscisaureus on |
I see. However, the types we don't support on Windows (remember we are on readdir / scandir) doen't seem to apply: character device, block device, fifo, local domain socket. Do they? |
That's correct. This means we also report "link" for mount points, but those behave very similar to symlinks on windows anyway (technically they're just directory junctions).
Those type of devices do exist on windows, but they cannot live in ordinary directories. Pipes all live in |
@piscisaureus Kewl! So, it looks like we have all our bases covered for |
@piscisaureus I think that API is only for device drivers. |
@saghul this looks like a much more improved, thanks! |
@orangemocha the API can be used from user land. The second link is a spec for driver implementors indeed, we are on the "consuming" end. |
Landed, thanks to everyone who helped! |
Some systems (hello SunOS!) don't have thr d_type field on struct
dirent, so mark them as UV_DIRENT_UNKNOWN, also mark anything not a
directory or a file as unknown.
Jenkins, give me some good news!