authorgravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-06 22:28:43-06:00
committergravatar for leroycepearson@geemili.xyzLeRoyce Pearson <leroycepearson@geemili.xyz> 2020-04-06 22:28:43-06:00
log20597c85968432e1de22f17d5593471eeb7475f2
tree57cd700d51e4c2c6e039258d9e1f20a76339059f
parent49886d2e452fd57f996795d92cd951649e4bc255

Only call `os.flock` on systems that lack openat locks


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

lib/std/fs.zig+8-11
......@@ -596,13 +596,12 @@ pub const Dir = struct {
596596 }
597597
598598 // Use the O_ locking flags if the os supports them
599 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK") and @hasDecl(os, "O_SHLOCK");
599600 const lock_flag: u32 = lock_flag: {
600 if (!flags.lock) break :lock_flag 0;
601 if (flags.write) {
602 break :lock_flag if (@hasDecl(os, "O_EXLOCK")) os.O_EXLOCK else 0;
603 } else {
604 break :lock_flag if (@hasDecl(os, "O_SHLOCK")) os.O_SHLOCK else 0;
601 if (has_flock_open_flags and flags.lock) {
602 break :lock_flag if (flags.write) os.O_EXLOCK else os.O_SHLOCK;
605603 }
604 break :lock_flag 0;
606605 };
607606
608607 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
......@@ -617,7 +616,7 @@ pub const Dir = struct {
617616 else
618617 try os.openatZ(self.fd, sub_path, os_flags, 0);
619618
620 if (flags.lock and lock_flag == 0) {
619 if (!has_flock_open_flags and flags.lock) {
621620 // TODO: integrate async I/O
622621 try os.flock(fd, if (flags.write) os.LOCK_EX else os.LOCK_SH);
623622 }
......@@ -672,10 +671,8 @@ pub const Dir = struct {
672671 }
673672
674673 // Use the O_ locking flags if the os supports them
675 const lock_flag: u32 = lock_flag: {
676 if (!flags.lock) break :lock_flag 0;
677 break :lock_flag if (@hasDecl(os, "O_EXLOCK")) os.O_EXLOCK else 0;
678 };
674 const has_flock_open_flags = @hasDecl(os, "O_EXLOCK");
675 const lock_flag: u32 = if (has_flock_open_flags and flags.lock) os.O_EXLOCK else 0;
679676
680677 const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0;
681678 const os_flags = lock_flag | O_LARGEFILE | os.O_CREAT | os.O_CLOEXEC |
......@@ -687,7 +684,7 @@ pub const Dir = struct {
687684 else
688685 try os.openatZ(self.fd, sub_path_c, os_flags, flags.mode);
689686
690 if (flags.lock and lock_flag == 0) {
687 if (!has_flock_open_flags and flags.lock) {
691688 // TODO: integrate async I/O
692689 try os.flock(fd, os.LOCK_EX);
693690 }