Skip to content

Fix FileType PartialEq implementation on Windows #138671

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

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

ChrisDenton
Copy link
Member

@ChrisDenton ChrisDenton commented Mar 18, 2025

Fixes #138668

On Windows the FileType struct was deriving PartialEq which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because attributes may contain many things unrelated to file type.

FileType on Windows allows for four possible combinations (see also FileTypeExt): file, dir, symlink_file and symlink_dir. So the new implementation makes sure both symlink and directory information match (and only those things).

This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 18, 2025
@ChrisDenton
Copy link
Member Author

@joshtriplett, since you won the dice roll, does this need an FCP?

@Kyuuhachi
Copy link
Contributor

Should probably fix the Hash too, because it currently breaks the a == b -> hash(a) == hash(b) property.

@ChrisDenton
Copy link
Member Author

Good point!

@ChrisDenton
Copy link
Member Author

ChrisDenton commented Mar 18, 2025

Actually this implementation would be so much simpler if I just calculated is_directory and is_symlink upfront instead of on-demand. The only reason to call file_type() is to use one of the FileType functions so I doubt it'll impact performance or anything. So I'll do that instead.

@joshtriplett
Copy link
Member

This seems correct to me. And I think it's a bugfix, not an API change.

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 22, 2025

📌 Commit 6b2fa32 has been approved by joshtriplett

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 24, 2025
Rollup of 10 pull requests

Successful merges:

 - rust-lang#137593 (fix download-llvm logic for subtree sync branches)
 - rust-lang#137736 (Don't attempt to export compiler-builtins symbols from rust dylibs)
 - rust-lang#138135 (Simplify `PartialOrd` on tuples containing primitives)
 - rust-lang#138321 ([bootstrap] Distribute split debuginfo if present)
 - rust-lang#138574 (rustdoc: be more strict about "Methods from Deref")
 - rust-lang#138606 (Fix missing rustfmt in msi installer - cont)
 - rust-lang#138671 (Fix `FileType` `PartialEq` implementation on Windows)
 - rust-lang#138728 (Update `compiler-builtins` to 0.1.152)
 - rust-lang#138783 (Cache current_dll_path output)
 - rust-lang#138846 (Tweaks to writeback and `Obligation -> Goal` conversion)

Failed merges:

 - rust-lang#138755 ([rustdoc] Remove duplicated loop when computing doc cfgs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8e30df7 into rust-lang:master Mar 24, 2025
6 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 24, 2025
Rollup merge of rust-lang#138671 - ChrisDenton:filetype, r=joshtriplett

Fix `FileType` `PartialEq` implementation on Windows

Fixes rust-lang#138668

On Windows the [`FileType`](https://doc.rust-lang.org/stable/std/fs/struct.FileType.html) struct was deriving `PartialEq` which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because `attributes` may contain many things unrelated to file type.

`FileType` on Windows allows for four possible combinations (see also [`FileTypeExt`](https://doc.rust-lang.org/stable/std/os/windows/fs/trait.FileTypeExt.html)): `file`, `dir`, `symlink_file` and `symlink_dir`. So the new implementation makes sure both symlink and directory information match (and only those things).

This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 2, 2025
Fix `FileType` `PartialEq` implementation on Windows

Fixes rust-lang#138668

On Windows the [`FileType`](https://doc.rust-lang.org/stable/std/fs/struct.FileType.html) struct was deriving `PartialEq` which in turn means it was doing a bit-for-bit comparison on the file attributes and reparse point. This is wrong because `attributes` may contain many things unrelated to file type.

`FileType` on Windows allows for four possible combinations (see also [`FileTypeExt`](https://doc.rust-lang.org/stable/std/os/windows/fs/trait.FileTypeExt.html)): `file`, `dir`, `symlink_file` and `symlink_dir`. So the new implementation makes sure both symlink and directory information match (and only those things).

This could be considered just a bug fix but it is a behaviour change so someone from libs-api might want to FCP this (or might not)...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent behavior in FileType comparisons on Windows
5 participants