authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-03 22:47:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-06 16:29:39-07:00
loga3d9cd1c1d9f1acbc9715a46bee76282e340e294
tree0f90a707c8779aa931a1b259bf43283b9826dfe1
parentca974de5217dbb7a638bd711df18fe9148383d3c

std.os: handle ETXTBSY from open()


3 files changed, 17 insertions(+), 1 deletions(-)

lib/std/fs.zig+2
...@@ -1481,6 +1481,7 @@ pub const Dir = struct {...@@ -1481,6 +1481,7 @@ pub const Dir = struct {
1481 error.PathAlreadyExists => unreachable, // not providing O.CREAT1481 error.PathAlreadyExists => unreachable, // not providing O.CREAT
1482 error.FileLocksNotSupported => unreachable, // locking folders is not supported1482 error.FileLocksNotSupported => unreachable, // locking folders is not supported
1483 error.WouldBlock => unreachable, // can't happen for directories1483 error.WouldBlock => unreachable, // can't happen for directories
1484 error.FileBusy => unreachable, // can't happen for directories
1484 else => |e| return e,1485 else => |e| return e,
1485 };1486 };
1486 return Dir{ .fd = fd };1487 return Dir{ .fd = fd };
...@@ -1525,6 +1526,7 @@ pub const Dir = struct {...@@ -1525,6 +1526,7 @@ pub const Dir = struct {
1525 error.PathAlreadyExists => unreachable, // not providing O.CREAT1526 error.PathAlreadyExists => unreachable, // not providing O.CREAT
1526 error.FileLocksNotSupported => unreachable, // locking folders is not supported1527 error.FileLocksNotSupported => unreachable, // locking folders is not supported
1527 error.WouldBlock => unreachable, // can't happen for directories1528 error.WouldBlock => unreachable, // can't happen for directories
1529 error.FileBusy => unreachable, // can't happen for directories
1528 else => |e| return e,1530 else => |e| return e,
1529 };1531 };
1530 return Dir{ .fd = fd };1532 return Dir{ .fd = fd };
lib/std/os.zig+14-1
...@@ -1275,6 +1275,16 @@ pub const OpenError = error{...@@ -1275,6 +1275,16 @@ pub const OpenError = error{
1275 BadPathName,1275 BadPathName,
1276 InvalidUtf8,1276 InvalidUtf8,
12771277
1278 /// One of these three things:
1279 /// * pathname refers to an executable image which is currently being
1280 /// executed and write access was requested.
1281 /// * pathname refers to a file that is currently in use as a swap
1282 /// file, and the O_TRUNC flag was specified.
1283 /// * pathname refers to a file that is currently being read by the
1284 /// kernel (e.g., for module/firmware loading), and write access was
1285 /// requested.
1286 FileBusy,
1287
1278 WouldBlock,1288 WouldBlock,
1279} || UnexpectedError;1289} || UnexpectedError;
12801290
...@@ -1468,6 +1478,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)...@@ -1468,6 +1478,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
1468 .BUSY => return error.DeviceBusy,1478 .BUSY => return error.DeviceBusy,
1469 .OPNOTSUPP => return error.FileLocksNotSupported,1479 .OPNOTSUPP => return error.FileLocksNotSupported,
1470 .AGAIN => return error.WouldBlock,1480 .AGAIN => return error.WouldBlock,
1481 .TXTBSY => return error.FileBusy,
1471 else => |err| return unexpectedErrno(err),1482 else => |err| return unexpectedErrno(err),
1472 }1483 }
1473 }1484 }
...@@ -4577,7 +4588,8 @@ pub const FlockError = error{...@@ -4577,7 +4588,8 @@ pub const FlockError = error{
4577 FileLocksNotSupported,4588 FileLocksNotSupported,
4578} || UnexpectedError;4589} || UnexpectedError;
45794590
4580/// Depending on the operating system `flock` may or may not interact with `fcntl` locks made by other processes.4591/// Depending on the operating system `flock` may or may not interact with
4592/// `fcntl` locks made by other processes.
4581pub fn flock(fd: fd_t, operation: i32) FlockError!void {4593pub fn flock(fd: fd_t, operation: i32) FlockError!void {
4582 while (true) {4594 while (true) {
4583 const rc = system.flock(fd, operation);4595 const rc = system.flock(fd, operation);
...@@ -4650,6 +4662,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP...@@ -4650,6 +4662,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
4650 const fd = openZ(pathname, flags, 0) catch |err| switch (err) {4662 const fd = openZ(pathname, flags, 0) catch |err| switch (err) {
4651 error.FileLocksNotSupported => unreachable,4663 error.FileLocksNotSupported => unreachable,
4652 error.WouldBlock => unreachable,4664 error.WouldBlock => unreachable,
4665 error.FileBusy => unreachable, // not asking for write permissions
4653 else => |e| return e,4666 else => |e| return e,
4654 };4667 };
4655 defer close(fd);4668 defer close(fd);
lib/std/zig/system/NativeTargetInfo.zig+1
...@@ -365,6 +365,7 @@ fn detectAbiAndDynamicLinker(...@@ -365,6 +365,7 @@ fn detectAbiAndDynamicLinker(
365 error.PipeBusy => unreachable,365 error.PipeBusy => unreachable,
366 error.FileLocksNotSupported => unreachable,366 error.FileLocksNotSupported => unreachable,
367 error.WouldBlock => unreachable,367 error.WouldBlock => unreachable,
368 error.FileBusy => unreachable, // opened without write permissions
368369
369 error.IsDir,370 error.IsDir,
370 error.NotDir,371 error.NotDir,