From 8ed75614223ad86de26ddde9b9dda1ccbeb7d8d3 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 24 Nov 2020 10:23:54 +0100 Subject: [PATCH] std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos --- lib/std/fs.zig | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index a20f9942f6..64bd166f38 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -729,12 +729,14 @@ pub const Dir = struct { } var os_flags: u32 = os.O_CLOEXEC; - // Use the O_ locking flags if the os supports them - // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) - const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin; + // Use the O_ locking flags if the os supports them to acquire the lock + // atomically. + const has_flock_open_flags = @hasDecl(os, "O_EXLOCK"); if (has_flock_open_flags) { + // Note that the O_NONBLOCK flag is removed after the openat() call + // is successful. const nonblocking_lock_flag: u32 = if (flags.lock_nonblocking) - os.O_NONBLOCK | os.O_SYNC + os.O_NONBLOCK else 0; os_flags |= switch (flags.lock) { @@ -870,11 +872,13 @@ pub const Dir = struct { return self.createFileW(path_w.span(), flags); } - // Use the O_ locking flags if the os supports them - // (Or if it's darwin, as darwin's `open` doesn't support the O_SYNC flag) - const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and !is_darwin; + // Use the O_ locking flags if the os supports them to acquire the lock + // atomically. + const has_flock_open_flags = @hasDecl(os, "O_EXLOCK"); + // Note that the O_NONBLOCK flag is removed after the openat() call + // is successful. const nonblocking_lock_flag: u32 = if (has_flock_open_flags and flags.lock_nonblocking) - os.O_NONBLOCK | os.O_SYNC + os.O_NONBLOCK else 0; const lock_flag: u32 = if (has_flock_open_flags) switch (flags.lock) {