| ... | @@ -744,6 +744,19 @@ pub const Dir = struct { | ... | @@ -744,6 +744,19 @@ pub const Dir = struct { |
| 744 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode) | 744 | try std.event.Loop.instance.?.openatZ(self.fd, sub_path_c, os_flags, flags.mode) |
| 745 | else | 745 | else |
| 746 | try os.openatC(self.fd, sub_path_c, os_flags, flags.mode); | 746 | try os.openatC(self.fd, sub_path_c, os_flags, flags.mode); |
| | 747 | |
| | 748 | if (flags.lock) { |
| | 749 | // TODO: integrate async I/O |
| | 750 | // mem.zeroes is used here because flock's structure can vary across architectures and systems |
| | 751 | var flock = mem.zeroes(os.Flock); |
| | 752 | flock.l_type = os.F_WRLCK; |
| | 753 | flock.l_whence = os.SEEK_SET; |
| | 754 | flock.l_start = 0; |
| | 755 | flock.l_len = 0; |
| | 756 | flock.l_pid = 0; |
| | 757 | try os.fcntlFlock(fd, .SetLockBlocking, &flock); |
| | 758 | } |
| | 759 | |
| 747 | return File{ .handle = fd, .io_mode = .blocking }; | 760 | return File{ .handle = fd, .io_mode = .blocking }; |
| 748 | } | 761 | } |
| 749 | | 762 | |
| ... | @@ -759,7 +772,12 @@ pub const Dir = struct { | ... | @@ -759,7 +772,12 @@ pub const Dir = struct { |
| 759 | @as(u32, w.FILE_OVERWRITE_IF) | 772 | @as(u32, w.FILE_OVERWRITE_IF) |
| 760 | else | 773 | else |
| 761 | @as(u32, w.FILE_OPEN_IF); | 774 | @as(u32, w.FILE_OPEN_IF); |
| 762 | return self.openFileWindows(sub_path_w, access_mask, null, creation); | 775 | |
| | 776 | const share_access = if (flags.lock) |
| | 777 | @as(os.windows.ULONG, w.FILE_SHARE_DELETE) |
| | 778 | else |
| | 779 | null; |
| | 780 | return self.openFileWindows(sub_path_w, access_mask, share_access, creation); |
| 763 | } | 781 | } |
| 764 | | 782 | |
| 765 | /// Deprecated; call `openFile` directly. | 783 | /// Deprecated; call `openFile` directly. |