| ... | ... | @@ -733,10 +733,10 @@ pub const Dir = struct { |
| 733 | 733 | // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) |
| 734 | 734 | const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin; |
| 735 | 735 | if (has_flock_open_flags) { |
| 736 | | const nonblocking_lock_flag = if (flags.lock_nonblocking) |
| 736 | const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) |
| 737 | 737 | os.O_NONBLOCK | os.O_SYNC |
| 738 | 738 | else |
| 739 | | @as(u32, 0); |
| 739 | 0; |
| 740 | 740 | os_flags |= switch (flags.lock) { |
| 741 | 741 | .None => @as(u32, 0), |
| 742 | 742 | .Shared => os.O_SHLOCK | nonblocking_lock_flag, |
| ... | ... | @@ -771,6 +771,22 @@ pub const Dir = struct { |
| 771 | 771 | }); |
| 772 | 772 | } |
| 773 | 773 | |
| 774 | if (has_flock_open_flags and flags.lock_nonblocking) { |
| 775 | var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) { |
| 776 | error.FileBusy => unreachable, |
| 777 | error.Locked => unreachable, |
| 778 | error.PermissionDenied => unreachable, |
| 779 | else => |e| return e, |
| 780 | }; |
| 781 | fl_flags &= ~@as(usize, os.O_NONBLOCK); |
| 782 | _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) { |
| 783 | error.FileBusy => unreachable, |
| 784 | error.Locked => unreachable, |
| 785 | error.PermissionDenied => unreachable, |
| 786 | else => |e| return e, |
| 787 | }; |
| 788 | } |
| 789 | |
| 774 | 790 | return File{ |
| 775 | 791 | .handle = fd, |
| 776 | 792 | .capable_io_mode = .blocking, |
| ... | ... | @@ -887,6 +903,22 @@ pub const Dir = struct { |
| 887 | 903 | }); |
| 888 | 904 | } |
| 889 | 905 | |
| 906 | if (has_flock_open_flags and flags.lock_nonblocking) { |
| 907 | var fl_flags = os.fcntl(fd, os.F_GETFL, 0) catch |err| switch (err) { |
| 908 | error.FileBusy => unreachable, |
| 909 | error.Locked => unreachable, |
| 910 | error.PermissionDenied => unreachable, |
| 911 | else => |e| return e, |
| 912 | }; |
| 913 | fl_flags &= ~@as(usize, os.O_NONBLOCK); |
| 914 | _ = os.fcntl(fd, os.F_SETFL, fl_flags) catch |err| switch (err) { |
| 915 | error.FileBusy => unreachable, |
| 916 | error.Locked => unreachable, |
| 917 | error.PermissionDenied => unreachable, |
| 918 | else => |e| return e, |
| 919 | }; |
| 920 | } |
| 921 | |
| 890 | 922 | return File{ |
| 891 | 923 | .handle = fd, |
| 892 | 924 | .capable_io_mode = .blocking, |