Skip to content

FileType PartialEq implementation is buggy on Unix #104900

Closed

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)

Activity

  1. krtab commented on Nov 29, 2022

    @krtab
    ContributorAuthor

    @rustbot claim

  2. krtab commented on Nov 29, 2022

    @krtab
    ContributorAuthor

    @rustbot label: +T-libs-api + Libs-Small

  3. rustbot commented on Nov 29, 2022

    @rustbot
    Collaborator

    Error: Parsing relabel command in comment failed: ...'libs-api +' | error: empty label at >| ' Libs-Smal'...

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

  4. krtab commented on Nov 29, 2022

    @krtab
    ContributorAuthor

    @rustbot label: +T-libs-api +Libs-Small

  5. rustbot commented on Nov 29, 2022

    @rustbot
    Collaborator

    Error: Label Libs-Small can only be set by Rust team members

    Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

  6. krtab commented on Nov 29, 2022

    @krtab
    ContributorAuthor

    @rustbot label: +T-libs-api

  7. added 2 commits that reference this issue on Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.T-libs-api[DEPRECATED; DO NOT USE]

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions