authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2021-09-24 20:09:31+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-25 15:55:15-04:00
log15f55b2805541276f491d255f60f501c8cbd1191
tree02fe74a4b2e65adf0b2508fe0e07fb3b294c91e7
parent42aa1ea115eca3dcc704eddf020ce87271a41174

os.flock: FreeBSD can return EOPNOTSUPP


2 files changed, 7 insertions(+), 0 deletions(-)

lib/std/fs/file.zig+2
......@@ -866,6 +866,7 @@ pub const File = struct {
866866
867867 pub const LockError = error{
868868 SystemResources,
869 FileLocksNotSupported,
869870 } || os.UnexpectedError;
870871
871872 /// Blocks when an incompatible lock is held by another process.
......@@ -928,6 +929,7 @@ pub const File = struct {
928929 return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) {
929930 error.WouldBlock => unreachable, // unlocking can't block
930931 error.SystemResources => unreachable, // We are deallocating resources.
932 error.FileLocksNotSupported => unreachable, // We already got the lock.
931933 error.Unexpected => unreachable, // Resource deallocation must succeed.
932934 };
933935 }
lib/std/os.zig+5
......@@ -4501,8 +4501,12 @@ pub const FlockError = error{
45014501
45024502 /// The kernel ran out of memory for allocating file locks
45034503 SystemResources,
4504
4505 /// The underlying filesystem does not support file locks
4506 FileLocksNotSupported,
45044507} || UnexpectedError;
45054508
4509/// Depending on the operating system `flock` may or may not interact with `fcntl` locks made by other processes.
45064510pub fn flock(fd: fd_t, operation: i32) FlockError!void {
45074511 while (true) {
45084512 const rc = system.flock(fd, operation);
......@@ -4513,6 +4517,7 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {
45134517 .INVAL => unreachable, // invalid parameters
45144518 .NOLCK => return error.SystemResources,
45154519 .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
4520 .OPNOTSUPP => return error.FileLocksNotSupported,
45164521 else => |err| return unexpectedErrno(err),
45174522 }
45184523 }