authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-24 10:23:54+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-11-24 10:23:54+01:00
log8ed75614223ad86de26ddde9b9dda1ccbeb7d8d3
tree657fb65789fa27a2f911bccca2a04e1aa4d225f9
parent26d20e39fcacda04b5f2e158dd38c293194e2f01

std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos


1 files changed, 12 insertions(+), 8 deletions(-)

lib/std/fs.zig+12-8
......@@ -729,12 +729,14 @@ pub const Dir = struct {
729729 }
730730
731731 var os_flags: u32 = os.O_CLOEXEC;
732 // Use the O_ locking flags if the os supports them
733 // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag)
734 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin;
732 // Use the O_ locking flags if the os supports them to acquire the lock
733 // atomically.
734 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
735735 if (has_flock_open_flags) {
736 // Note that the O_NONBLOCK flag is removed after the openat() call
737 // is successful.
736738 const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking)
737 os.O_NONBLOCK | os.O_SYNC
739 os.O_NONBLOCK
738740 else
739741 0;
740742 os_flags |= switch (flags.lock) {
......@@ -870,11 +872,13 @@ pub const Dir = struct {
870872 return self.createFileW(path_w.span(), flags);
871873 }
872874
873 // Use the O_ locking flags if the os supports them
874 // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag)
875 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin;
875 // Use the O_ locking flags if the os supports them to acquire the lock
876 // atomically.
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.
876880 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
878882 else
879883 0;
880884 const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {