diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-11-24 10:23:54 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-11-24 10:23:54 +0100 |
| commit | 8ed75614223ad86de26ddde9b9dda1ccbeb7d8d3 (patch) | |
| tree | 657fb65789fa27a2f911bccca2a04e1aa4d225f9 /lib/std | |
| parent | 26d20e39fcacda04b5f2e158dd38c293194e2f01 (diff) | |
| download | zig-8ed75614223ad86de26ddde9b9dda1ccbeb7d8d3.tar.gz zig-8ed75614223ad86de26ddde9b9dda1ccbeb7d8d3.zip | |
std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/fs.zig | 20 |
1 files 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) { |
