mirror of
https://github.com/allankoechke/rust.git
synced 2026-12-02 17:44:28 +00:00
Fix(lib/fs/win): Fall back on Win32 delete for `Dir::remove_file`
The `test_dir_remove_file` test currently fails under Windows 7 on:
```
thread 'fs::tests::test_dir_remove_file' (2028) panicked at library/std/src/fs/tests.rs:2590:5:
dir.remove_file("foo.txt") failed with: The parameter is incorrect. (os error 87)
```
Looking into it, this is because the `FILE_DISPOSITION_INFO_EX` variant of the `SetFileInformationByHandle` API is used while it is only available starting from Windows 10 1607. However, `FILE_DISPOSITION_INFO` is still available since Vista.
This is therefore fixed by introducing a fallback to the latter API if the former fails. This is achieved by re-using some logic that is already available through `File::delete` and that does exactly this.
cc rust-lang/rust#120426 @roblabla @the8472 @ChrisDenton @RalfJung
@rustbot label A-io T-libs O-Windows-7