authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-15 15:47:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-15 15:47:42-04:00
loge36978906214cb8c3dba693a073914394a90d0d8
treecf3da4a709773dae9c5a23ba0aafa65bde3bb4a9
parent6c2b23593b97aef6f375bd7d81beeaf0f66f5682

fix std.os.renameatW

Ask for DELETE access when opening the source file. Additionally, when the source and dest dir are the same, pass null for RootDirectory.

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

lib/std/os.zig+2-2
...@@ -1650,7 +1650,7 @@ pub fn renameatW(...@@ -1650,7 +1650,7 @@ pub fn renameatW(
1650 new_path_w: [*:0]const u16,1650 new_path_w: [*:0]const u16,
1651 ReplaceIfExists: windows.BOOLEAN,1651 ReplaceIfExists: windows.BOOLEAN,
1652) RenameError!void {1652) RenameError!void {
1653 const access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE;1653 const access_mask = windows.SYNCHRONIZE | windows.GENERIC_WRITE | windows.DELETE;
1654 const src_fd = try windows.OpenFileW(old_dir_fd, old_path, null, access_mask, windows.FILE_OPEN);1654 const src_fd = try windows.OpenFileW(old_dir_fd, old_path, null, access_mask, windows.FILE_OPEN);
1655 defer windows.CloseHandle(src_fd);1655 defer windows.CloseHandle(src_fd);
16561656
...@@ -1664,7 +1664,7 @@ pub fn renameatW(...@@ -1664,7 +1664,7 @@ pub fn renameatW(
16641664
1665 rename_info.* = .{1665 rename_info.* = .{
1666 .ReplaceIfExists = ReplaceIfExists,1666 .ReplaceIfExists = ReplaceIfExists,
1667 .RootDirectory = if (std.fs.path.isAbsoluteWindowsW(new_path_w)) null else new_dir_fd,1667 .RootDirectory = if (old_dir_fd == new_dir_fd or std.fs.path.isAbsoluteWindowsW(new_path_w)) null else new_dir_fd,
1668 .FileNameLength = @intCast(u32, new_path.len * 2), // already checked error.NameTooLong1668 .FileNameLength = @intCast(u32, new_path.len * 2), // already checked error.NameTooLong
1669 .FileName = undefined,1669 .FileName = undefined,
1670 };1670 };