| ... | ... | @@ -596,13 +596,12 @@ pub const Dir = struct { |
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | // 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"); |
| 599 | 600 | 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; |
| 605 | 603 | } |
| 604 | break :lock_flag 0; |
| 606 | 605 | }; |
| 607 | 606 | |
| 608 | 607 | const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0; |
| ... | ... | @@ -617,7 +616,7 @@ pub const Dir = struct { |
| 617 | 616 | else |
| 618 | 617 | try os.openatZ(self.fd, sub_path, os_flags, 0); |
| 619 | 618 | |
| 620 | | if (flags.lock and lock_flag == 0) { |
| 619 | if (!has_flock_open_flags and flags.lock) { |
| 621 | 620 | // TODO: integrate async I/O |
| 622 | 621 | try os.flock(fd, if (flags.write) os.LOCK_EX else os.LOCK_SH); |
| 623 | 622 | } |
| ... | ... | @@ -672,10 +671,8 @@ pub const Dir = struct { |
| 672 | 671 | } |
| 673 | 672 | |
| 674 | 673 | // 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; |
| 679 | 676 | |
| 680 | 677 | const O_LARGEFILE = if (@hasDecl(os, "O_LARGEFILE")) os.O_LARGEFILE else 0; |
| 681 | 678 | const os_flags = lock_flag | O_LARGEFILE | os.O_CREAT | os.O_CLOEXEC | |
| ... | ... | @@ -687,7 +684,7 @@ pub const Dir = struct { |
| 687 | 684 | else |
| 688 | 685 | try os.openatZ(self.fd, sub_path_c, os_flags, flags.mode); |
| 689 | 686 | |
| 690 | | if (flags.lock and lock_flag == 0) { |
| 687 | if (!has_flock_open_flags and flags.lock) { |
| 691 | 688 | // TODO: integrate async I/O |
| 692 | 689 | try os.flock(fd, os.LOCK_EX); |
| 693 | 690 | } |