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