-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Inconsistent behavior in FileType comparisons on Windows #138668
Comments
When this was brought up on Discord, I also noticed that rust/library/std/src/sys/fs/windows.rs Lines 1068 to 1073 in 259fdb5
rust/library/std/src/sys/fs/windows.rs Lines 177 to 180 in 259fdb5
|
While not ideal, that part is technically "fine" because |
Except for equality. I haven't tested, but I think the FileType returned from a DirEntry and from a Metadata might not compare equal, even for the same file. |
I submitted a fix (see above) that only compares the relevant information, so let's see what the libs-api team says. |
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)...
The
PartialEq
/Eq
implementation of FileType on Windows is currently comparing more than just the actual file type. It seems to be using all file attributes for the comparison instead.Steps to reproduce:
a.txt
andb.txt
The following test will now fail:
Expected behavior:
I would expect the comparison between two
FileType
s to only compare the actual file TYPE (e.g. file, dir, symlink, any platform-specific extensions), but not file attributes.Another issue in this case is that it isn't obvious why the comparison fails, because
FileType
's Debug implementation only showsis_file
,is_dir
, andis_symlink
:I'm not sure whether this is something that can be easily fixed - I'd argue it should be considered an actual bug occurring in an edge case, but fixing it would technically introduce a breaking change.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: