Skip to content

Fix & Improve doc comment on some structures #167

@minghu6

Description

@minghu6

Fix staled comments on DirList, DirEntry, IntoIter

It's said that these structure relies on std::fs::DirEntry which is outdated since we use our crate::dent::DirEntry

Supply additional comment for difference between std DirEntry and our DirEntry

I've no idea if we've noticed that std DirEntry hold a reference of opened dir as the documented mentioned.

In a detail, on Unix implementaions:

ReadDir holds an Arc of InnerReadDir, and it shares it with DirEntry.

readdir

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L1296

ReadDir

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L231

Impl Iterator for ReadDir

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L587

DirEntry

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L257

The InnderReadDir holds the Dir which is an wrapper of platform native opaque DIR.

DIR

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L244

When the InnerReadDir is dropped, it calls native closedir would close underlying fd associated.

impl Drop for Dir

https://github.com/rust-lang/rust/blob/aa8e761defc245d08d2cf226786def8a8bb56e53/library/std/src/sys/unix/fs.rs#L687

closedir

https://man7.org/linux/man-pages/man3/closedir.3.html
https://pubs.opengroup.org/onlinepubs/9699919799.2016edition/toc.htm

In other words, If we keep the DirEntry, the InnerReader inner Arc wouldn't be dropped, that's: directory fd wouldn't be released even through we drop ReadDir through max_open control ! So, we could encounter Too many open files error when using collect on the iteration when walking a big enough directory !

However, luckily, we use our impl DirEntry instead of std version since it doesnt hold the fd reference. We just need to document it as additional doc comment before our DirEntry!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions