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 {...@@ -729,12 +729,14 @@ pub const Dir = struct {
729 }729 }
730730
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 them732 // 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_SYNC739 os.O_NONBLOCK
738 else740 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 }
872874
873 // Use the O_ locking flags if the os supports them875 // 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_SYNC881 os.O_NONBLOCK
878 else882 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) {