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 {...@@ -866,6 +866,7 @@ pub const File = struct {
866866
867 pub const LockError = error{867 pub const LockError = error{
868 SystemResources,868 SystemResources,
869 FileLocksNotSupported,
869 } || os.UnexpectedError;870 } || os.UnexpectedError;
870871
871 /// Blocks when an incompatible lock is held by another process.872 /// Blocks when an incompatible lock is held by another process.
...@@ -928,6 +929,7 @@ pub const File = struct {...@@ -928,6 +929,7 @@ pub const File = struct {
928 return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) {929 return os.flock(file.handle, os.LOCK.UN) catch |err| switch (err) {
929 error.WouldBlock => unreachable, // unlocking can't block930 error.WouldBlock => unreachable, // unlocking can't block
930 error.SystemResources => unreachable, // We are deallocating resources.931 error.SystemResources => unreachable, // We are deallocating resources.
932 error.FileLocksNotSupported => unreachable, // We already got the lock.
931 error.Unexpected => unreachable, // Resource deallocation must succeed.933 error.Unexpected => unreachable, // Resource deallocation must succeed.
932 };934 };
933 }935 }
lib/std/os.zig+5
...@@ -4501,8 +4501,12 @@ pub const FlockError = error{...@@ -4501,8 +4501,12 @@ pub const FlockError = error{
45014501
4502 /// The kernel ran out of memory for allocating file locks4502 /// The kernel ran out of memory for allocating file locks
4503 SystemResources,4503 SystemResources,
4504
4505 /// The underlying filesystem does not support file locks
4506 FileLocksNotSupported,
4504} || UnexpectedError;4507} || UnexpectedError;
45054508
4509/// Depending on the operating system `flock` may or may not interact with `fcntl` locks made by other processes.
4506pub fn flock(fd: fd_t, operation: i32) FlockError!void {4510pub fn flock(fd: fd_t, operation: i32) FlockError!void {
4507 while (true) {4511 while (true) {
4508 const rc = system.flock(fd, operation);4512 const rc = system.flock(fd, operation);
...@@ -4513,6 +4517,7 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {...@@ -4513,6 +4517,7 @@ pub fn flock(fd: fd_t, operation: i32) FlockError!void {
4513 .INVAL => unreachable, // invalid parameters4517 .INVAL => unreachable, // invalid parameters
4514 .NOLCK => return error.SystemResources,4518 .NOLCK => return error.SystemResources,
4515 .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error4519 .AGAIN => return error.WouldBlock, // TODO: integrate with async instead of just returning an error
4520 .OPNOTSUPP => return error.FileLocksNotSupported,
4516 else => |err| return unexpectedErrno(err),4521 else => |err| return unexpectedErrno(err),
4517 }4522 }
4518 }4523 }