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