mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
os.flock: FreeBSD can return EOPNOTSUPP
This commit is contained in:
parent
42aa1ea115
commit
15f55b2805
@ -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.
|
||||
};
|
||||
}
|
||||
|
||||
@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user