Skip to content
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

FileType PartialEq implementation is buggy on Unix #104900

Closed
krtab opened this issue Nov 25, 2022 · 6 comments · Fixed by #104901
Closed

FileType PartialEq implementation is buggy on Unix #104900

krtab opened this issue Nov 25, 2022 · 6 comments · Fixed by #104901
Assignees
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@krtab
Copy link
Contributor

krtab commented Nov 25, 2022

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)

@krtab krtab added the C-bug Category: This is a bug. label Nov 25, 2022
@krtab
Copy link
Contributor Author

krtab commented Nov 29, 2022

@rustbot claim

@krtab
Copy link
Contributor Author

krtab commented Nov 29, 2022

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

@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2022

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.

@krtab
Copy link
Contributor Author

krtab commented Nov 29, 2022

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

@rustbot
Copy link
Collaborator

rustbot commented Nov 29, 2022

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.

@krtab
Copy link
Contributor Author

krtab commented Nov 29, 2022

@rustbot label: +T-libs-api

@rustbot rustbot added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Nov 29, 2022
krtab added a commit to krtab/rust that referenced this issue Nov 30, 2022
krtab added a commit to krtab/rust that referenced this issue Dec 6, 2022
Commit 7700595 implemented masking of
FileType to fix an issue[^1] in the semantic of FileType comparison.
This commit introduces masking to Hash to maintain the invariant that
x == y => hash(x) == hash(y).

[^1]: rust-lang#104900
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 10, 2022
Implement masking in FileType comparison on Unix

Fixes: rust-lang#104900
@bors bors closed this as completed in 7700595 Dec 10, 2022
thomcc pushed a commit to tcdi/postgrestd that referenced this issue May 31, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue May 31, 2023
thomcc pushed a commit to tcdi/postgrestd that referenced this issue May 31, 2023
Commit 77005950f09d2f9ba54962bf5adc3f2bc3a7213f implemented masking of
FileType to fix an issue[^1] in the semantic of FileType comparison.
This commit introduces masking to Hash to maintain the invariant that
x == y => hash(x) == hash(y).

[^1]: rust-lang/rust#104900
thomcc pushed a commit to tcdi/postgrestd that referenced this issue May 31, 2023
Implement masking in FileType comparison on Unix

Fixes: rust-lang/rust#104900
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants