| ... | @@ -729,12 +729,14 @@ pub const Dir = struct { | ... | @@ -729,12 +729,14 @@ pub const Dir = struct { |
| 729 | } | 729 | } |
| 730 | | 730 | |
| 731 | var os_flags: u32 = os.O_CLOEXEC; | 731 | var os_flags: u32 = os.O_CLOEXEC; |
| 732 | // Use the O_ locking flags if the os supports them | 732 | // Use the O_ locking flags if the os supports them to acquire the lock |
| 733 | // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) | 733 | // atomically. |
| 734 | const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin; | 734 | const has_flock_open_flags = @hasDecl(os, "O_EXLOCK"); |
| 735 | if (has_flock_open_flags) { | 735 | if (has_flock_open_flags) { |
| | 736 | // Note that the O_NONBLOCK flag is removed after the openat() call |
| | 737 | // is successful. |
| 736 | const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) | 738 | const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) |
| 737 | os.O_NONBLOCK | os.O_SYNC | 739 | os.O_NONBLOCK |
| 738 | else | 740 | else |
| 739 | 0; | 741 | 0; |
| 740 | os_flags |= switch (flags.lock) { | 742 | os_flags |= switch (flags.lock) { |
| ... | @@ -870,11 +872,13 @@ pub const Dir = struct { | ... | @@ -870,11 +872,13 @@ pub const Dir = struct { |
| 870 | return self.createFileW(path_w.span(), flags); | 872 | return self.createFileW(path_w.span(), flags); |
| 871 | } | 873 | } |
| 872 | | 874 | |
| 873 | // Use the O_ locking flags if the os supports them | 875 | // Use the O_ locking flags if the os supports them to acquire the lock |
| 874 | // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) | 876 | // atomically. |
| 875 | const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin; | 877 | const has_flock_open_flags = @hasDecl(os, "O_EXLOCK"); |
| | 878 | // Note that the O_NONBLOCK flag is removed after the openat() call |
| | 879 | // is successful. |
| 876 | const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking) | 880 | const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking) |
| 877 | os.O_NONBLOCK | os.O_SYNC | 881 | os.O_NONBLOCK |
| 878 | else | 882 | else |
| 879 | 0; | 883 | 0; |
| 880 | const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) { | 884 | const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) { |