@@ -577,6 +577,35 @@ pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path:
577
577
}
578
578
579
579
pub fn deleteFile (allocator : & Allocator , file_path : []const u8 ) - > % void {
580
+ if (builtin .os == Os .windows ) {
581
+ return deleteFileWindows (allocator , file_path );
582
+ } else {
583
+ return deleteFilePosix (allocator , file_path );
584
+ }
585
+ }
586
+
587
+ error FileNotFound ;
588
+ error AccessDenied ;
589
+
590
+ pub fn deleteFileWindows (allocator : & Allocator , file_path : []const u8 ) - > % void {
Has conversations. Original line has conversations.
591
+ const buf = % return allocator .alloc (u8 , file_path .len + 1 );
592
+ defer allocator .free (buf );
593
+
594
+ mem .copy (u8 , buf , file_path );
595
+ buf [file_path .len ] = 0 ;
596
+
597
+ if (! windows .DeleteFileA (buf .ptr )) {
598
+ const err = windows .GetLastError ();
599
+ return switch (err ) {
600
+ windows .ERROR .FILE_NOT_FOUND = > error .FileNotFound ,
601
+ windows .ERROR .ACCESS_DENIED = > error .AccessDenied ,
602
+ windows .ERROR .FILENAME_EXCED_RANGE , windows .ERROR .INVALID_PARAMETER = > error .NameTooLong ,
603
+ else = > error .Unexpected ,
604
+ }
605
+ }
606
+ }
607
+
608
+ pub fn deleteFilePosix (allocator : & Allocator , file_path : []const u8 ) - > % void {
580
609
const buf = % return allocator .alloc (u8 , file_path .len + 1 );
581
610
defer allocator .free (buf );
582
611