From d7ec7cf96e1b863eaea1ec29c76343c4c65e1337 Mon Sep 17 00:00:00 2001 From: George Tokmaji Date: Thu, 17 Oct 2024 00:27:46 +0200 Subject: [PATCH] Win: Remove special casing of the win7 target for `std::fs::rename` --- std/src/sys/pal/windows/fs.rs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/std/src/sys/pal/windows/fs.rs b/std/src/sys/pal/windows/fs.rs index 85ad773ca8095..2d584ec051401 100644 --- a/std/src/sys/pal/windows/fs.rs +++ b/std/src/sys/pal/windows/fs.rs @@ -1316,11 +1316,7 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> { // SAFETY: We have allocated enough memory for a full FILE_RENAME_INFO struct and a filename. unsafe { (&raw mut (*file_rename_info).Anonymous).write(c::FILE_RENAME_INFO_0 { - // Don't bother with FileRenameInfo on Windows 7 since it doesn't exist. - #[cfg(not(target_vendor = "win7"))] Flags: c::FILE_RENAME_FLAG_REPLACE_IF_EXISTS | c::FILE_RENAME_FLAG_POSIX_SEMANTICS, - #[cfg(target_vendor = "win7")] - ReplaceIfExists: 1, }); (&raw mut (*file_rename_info).RootDirectory).write(ptr::null_mut()); @@ -1330,22 +1326,16 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> { .copy_to_nonoverlapping((&raw mut (*file_rename_info).FileName) as *mut u16, new.len()); } - #[cfg(not(target_vendor = "win7"))] - const FileInformationClass: c::FILE_INFO_BY_HANDLE_CLASS = c::FileRenameInfoEx; - #[cfg(target_vendor = "win7")] - const FileInformationClass: c::FILE_INFO_BY_HANDLE_CLASS = c::FileRenameInfo; - // We don't use `set_file_information_by_handle` here as `FILE_RENAME_INFO` is used for both `FileRenameInfo` and `FileRenameInfoEx`. let result = unsafe { cvt(c::SetFileInformationByHandle( handle.as_raw_handle(), - FileInformationClass, + c::FileRenameInfoEx, (&raw const *file_rename_info).cast::(), struct_size, )) }; - #[cfg(not(target_vendor = "win7"))] if let Err(err) = result { if err.raw_os_error() == Some(c::ERROR_INVALID_PARAMETER as _) { // FileRenameInfoEx and FILE_RENAME_FLAG_POSIX_SEMANTICS were added in Windows 10 1607; retry with FileRenameInfo. @@ -1364,9 +1354,6 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> { } } - #[cfg(target_vendor = "win7")] - result?; - Ok(()) }