From 15f55b2805541276f491d255f60f501c8cbd1191 Mon Sep 17 00:00:00 2001 From: xackus <14938807+xackus@users.noreply.github.com> Date: Fri, 24 Sep 2021 20:09:31 +0200 Subject: [PATCH] os.flock: FreeBSD can return EOPNOTSUPP --- lib/std/fs/file.zig | 2 ++ lib/std/os.zig | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index fd0492f0bf..a71c9ae0d2 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -866,6 +866,7 @@ pub const File = struct { pub const LockError = error{ SystemResources, + FileLocksNotSupported, } || os.UnexpectedError; /// Blocks when an incompatible lock is held by another process. @@ -928,6 +929,7 @@ pub const File = struct { return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) { error.WouldBlock => unreachable, // unlocking can't block error.SystemResources => unreachable, // We are deallocating resources. + error.FileLocksNotSupported => unreachable, // We already got the lock. error.Unexpected => unreachable, // Resource deallocation must succeed. }; } diff --git a/lib/std/os.zig b/lib/std/os.zig index d85815dde0..a4fad9bc20 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -4501,8 +4501,12 @@ pub const FlockError = error{ /// The kernel ran out of memory for allocating file locks SystemResources, + + /// The underlying filesystem does not support file locks + FileLocksNotSupported, } || UnexpectedError; +/// Depending on the operating system `flock` may or may not interact with `fcntl` locks made by other processes. pub fn flock(fd: fd_t, operation: i32) FlockError!void { while (true) { const rc = system.flock(fd, operation); @@ -4513,6 +4517,7 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void { .INVAL => unreachable, // invalid parameters .NOLCK => return error.SystemResources, .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error + .OPNOTSUPP => return error.FileLocksNotSupported, else => |err| return unexpectedErrno(err), } }