Skip to content

FileType PartialEq implementation is buggy on Unix #104900

Closed
@krtab

Description

@krtab

I tried this code:

fn main() {
    fs::create_dir("dir").unwrap();
    File::create("dir/file").unwrap();
    for e in read_dir("dir").unwrap() {
        let e = e.unwrap();
        let p = e.path();
        let ft1 = e.file_type().unwrap();
        let ft2 = p.metadata().unwrap().file_type();
        assert_eq!(ft1, ft2);
    }
}

This currently fails, even though no symlinks are involved.

This is because FileType on Unix are currently compared on the totality of their contained unix st_mode, which are bitflags of the form ...YYY0XXX (in octal) where XXX is a Unix permission mode and ...YYY the actual file type. As of now, depending on how the FileType is built, XXX may be either 000 (from DirEntry::filetype) or set to the actual file permission mode (if built from fs::metadata).

(This bug was co-investigated with @hernoufM)

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions