os.flock: FreeBSD can return EOPNOTSUPP

This commit is contained in:
xackus 2021-09-24 20:09:31 +02:00 committed by Andrew Kelley
parent 42aa1ea115
commit 15f55b2805
2 changed files with 7 additions and 0 deletions

View File

@ -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.
};
}

View File

@ -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),
}
}