| ... | ... | @@ -764,6 +764,7 @@ pub const DeleteFileError = error{ |
| 764 | 764 | Unexpected, |
| 765 | 765 | NotDir, |
| 766 | 766 | IsDir, |
| 767 | DirNotEmpty, |
| 767 | 768 | }; |
| 768 | 769 | |
| 769 | 770 | pub const DeleteFileOptions = struct { |
| ... | ... | @@ -818,7 +819,7 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil |
| 818 | 819 | 0, |
| 819 | 820 | ); |
| 820 | 821 | switch (rc) { |
| 821 | | .SUCCESS => return CloseHandle(tmp_handle), |
| 822 | .SUCCESS => CloseHandle(tmp_handle), |
| 822 | 823 | .OBJECT_NAME_INVALID => unreachable, |
| 823 | 824 | .OBJECT_NAME_NOT_FOUND => return error.FileNotFound, |
| 824 | 825 | .INVALID_PARAMETER => unreachable, |
| ... | ... | @@ -826,6 +827,21 @@ pub fn DeleteFile(sub_path_w: []const u16, options: DeleteFileOptions) DeleteFil |
| 826 | 827 | .NOT_A_DIRECTORY => return error.NotDir, |
| 827 | 828 | else => return unexpectedStatus(rc), |
| 828 | 829 | } |
| 830 | |
| 831 | // If a directory fails to be deleted, CloseHandle will still report success |
| 832 | // Check if the directory still exists and return error.DirNotEmpty if true |
| 833 | if (options.remove_dir) { |
| 834 | var basic_info: FILE_BASIC_INFORMATION = undefined; |
| 835 | switch (ntdll.NtQueryAttributesFile(&attr, &basic_info)) { |
| 836 | .SUCCESS => return error.DirNotEmpty, |
| 837 | .OBJECT_NAME_NOT_FOUND => return, |
| 838 | .OBJECT_PATH_NOT_FOUND => return, |
| 839 | .INVALID_PARAMETER => unreachable, |
| 840 | .ACCESS_DENIED => return error.AccessDenied, |
| 841 | .OBJECT_PATH_SYNTAX_BAD => unreachable, |
| 842 | else => |urc| return unexpectedStatus(urc), |
| 843 | } |
| 844 | } |
| 829 | 845 | } |
| 830 | 846 | |
| 831 | 847 | pub const MoveFileError = error{ FileNotFound, Unexpected }; |