authorgravatar for jan.hafer@rwth-aachen.deJan Philipp Hafer <jan.hafer@rwth-aachen.de> 2023-09-02 12:55:22+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-03 08:35:26+02:00
log1816bb4ab050f46504a2f1e827e9d74f8d253101
tree5d671fc099d1aeb3fc1b06e18beb5037ccec4b20
parente265dc61e651d67bbfb3be675ff132df865902ef

std.os+windows: isAtLeast(.win10_rs5) in renameatW(), DeleteFile() for posix semantics

Usage of FILE_RENAME_IGNORE_READONLY_ATTRIBUTE or FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE for posix semantics require win10_rs5 instead of win10_rs1 necessary for posix semantics. Keep it as simple as possible, since it is reasonable to expect users being able to update win10_rs5 or use non-posix semantics instead. Closes #17049.

2 files changed, 9 insertions(+), 2 deletions(-)

lib/std/os.zig+7-1
......@@ -2631,7 +2631,13 @@ pub fn renameatW(
26312631
26322632 var need_fallback = true;
26332633 var rc: windows.NTSTATUS = undefined;
2634 if (comptime builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs1)) {
2634 // FILE_RENAME_INFORMATION_EX and FILE_RENAME_POSIX_SEMANTICS require >= win10_rs1,
2635 // but FILE_RENAME_IGNORE_READONLY_ATTRIBUTE requires >= win10_rs5. We check >= rs5 here
2636 // so that we only use POSIX_SEMANTICS when we know IGNORE_READONLY_ATTRIBUTE will also be
2637 // supported in order to avoid either (1) using a redundant call that we can know in advance will return
2638 // STATUS_NOT_SUPPORTED or (2) only setting IGNORE_READONLY_ATTRIBUTE when >= rs5
2639 // and therefore having different behavior when the Windows version is >= rs1 but < rs5.
2640 if (comptime builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs5)) {
26352641 const struct_buf_len = @sizeOf(windows.FILE_RENAME_INFORMATION_EX) + (MAX_PATH_BYTES - 1);
26362642 var rename_info_buf: [struct_buf_len]u8 align(@alignOf(windows.FILE_RENAME_INFORMATION_EX)) = undefined;
26372643 const struct_len = @sizeOf(windows.FILE_RENAME_INFORMATION_EX) - 1 + new_path_w.len * 2;
lib/std/os/windows.zig+2-1
......@@ -992,8 +992,9 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil
992992 // are only supported on NTFS filesystems, so the version check on its own is only a partial solution. To support non-NTFS filesystems
993993 // like FAT32, we need to fallback to FileDispositionInformation if the usage of FileDispositionInformationEx gives
994994 // us INVALID_PARAMETER.
995 // The same reasoning for win10_rs5 as in os.renameatW() applies (FILE_DISPOSITION_IGNORE_READONLY_ATTRIBUTE requires >= win10_rs5).
995996 var need_fallback = true;
996 if (comptime builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs1)) {
997 if (comptime builtin.target.os.version_range.windows.min.isAtLeast(.win10_rs5)) {
997998 // Deletion with posix semantics if the filesystem supports it.
998999 var info = FILE_DISPOSITION_INFORMATION_EX{
9991000 .Flags = FILE_DISPOSITION_DELETE |