| ... | @@ -674,26 +674,36 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) | ... | @@ -674,26 +674,36 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8) |
| 674 | mem.copy(u8, new_buf, new_path); | 674 | mem.copy(u8, new_buf, new_path); |
| 675 | new_buf[new_path.len] = 0; | 675 | new_buf[new_path.len] = 0; |
| 676 | | 676 | |
| 677 | const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr)); | 677 | if (is_windows) { |
| 678 | if (err > 0) { | 678 | const flags = windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_WRITE_THROUGH; |
| 679 | return switch (err) { | 679 | if (!windows.MoveFileExA(old_buf.ptr, new_buf.ptr, flags)) { |
| 680 | posix.EACCES, posix.EPERM => error.AccessDenied, | 680 | const err = windows.GetLastError(); |
| 681 | posix.EBUSY => error.FileBusy, | 681 | return switch (err) { |
| 682 | posix.EDQUOT => error.DiskQuota, | 682 | else => return error.Unexpected, |
| 683 | posix.EFAULT, posix.EINVAL => unreachable, | 683 | }; |
| 684 | posix.EISDIR => error.IsDir, | 684 | } |
| 685 | posix.ELOOP => error.SymLinkLoop, | 685 | } else { |
| 686 | posix.EMLINK => error.LinkQuotaExceeded, | 686 | const err = posix.getErrno(posix.rename(old_buf.ptr, new_buf.ptr)); |
| 687 | posix.ENAMETOOLONG => error.NameTooLong, | 687 | if (err > 0) { |
| 688 | posix.ENOENT => error.FileNotFound, | 688 | return switch (err) { |
| 689 | posix.ENOTDIR => error.NotDir, | 689 | posix.EACCES, posix.EPERM => error.AccessDenied, |
| 690 | posix.ENOMEM => error.SystemResources, | 690 | posix.EBUSY => error.FileBusy, |
| 691 | posix.ENOSPC => error.NoSpaceLeft, | 691 | posix.EDQUOT => error.DiskQuota, |
| 692 | posix.EEXIST, posix.ENOTEMPTY => error.PathAlreadyExists, | 692 | posix.EFAULT, posix.EINVAL => unreachable, |
| 693 | posix.EROFS => error.ReadOnlyFileSystem, | 693 | posix.EISDIR => error.IsDir, |
| 694 | posix.EXDEV => error.RenameAcrossMountPoints, | 694 | posix.ELOOP => error.SymLinkLoop, |
| 695 | else => error.Unexpected, | 695 | posix.EMLINK => error.LinkQuotaExceeded, |
| 696 | }; | 696 | posix.ENAMETOOLONG => error.NameTooLong, |
| | 697 | posix.ENOENT => error.FileNotFound, |
| | 698 | posix.ENOTDIR => error.NotDir, |
| | 699 | posix.ENOMEM => error.SystemResources, |
| | 700 | posix.ENOSPC => error.NoSpaceLeft, |
| | 701 | posix.EEXIST, posix.ENOTEMPTY => error.PathAlreadyExists, |
| | 702 | posix.EROFS => error.ReadOnlyFileSystem, |
| | 703 | posix.EXDEV => error.RenameAcrossMountPoints, |
| | 704 | else => error.Unexpected, |
| | 705 | }; |
| | 706 | } |
| 697 | } | 707 | } |
| 698 | } | 708 | } |
| 699 | | 709 | |