Skip to content

Commit a3d9cd1

Browse files
committed
std.os: handle ETXTBSY from open()
1 parent ca974de commit a3d9cd1

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/std/fs.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ pub const Dir = struct {
14811481
error.PathAlreadyExists => unreachable, // not providing O.CREAT
14821482
error.FileLocksNotSupported => unreachable, // locking folders is not supported
14831483
error.WouldBlock => unreachable, // can't happen for directories
1484+
error.FileBusy => unreachable, // can't happen for directories
14841485
else => |e| return e,
14851486
};
14861487
return Dir{ .fd = fd };
@@ -1525,6 +1526,7 @@ pub const Dir = struct {
15251526
error.PathAlreadyExists => unreachable, // not providing O.CREAT
15261527
error.FileLocksNotSupported => unreachable, // locking folders is not supported
15271528
error.WouldBlock => unreachable, // can't happen for directories
1529+
error.FileBusy => unreachable, // can't happen for directories
15281530
else => |e| return e,
15291531
};
15301532
return Dir{ .fd = fd };

lib/std/os.zig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,16 @@ pub const OpenError = error{
12751275
BadPathName,
12761276
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+
12781288
WouldBlock,
12791289
} || UnexpectedError;
12801290

@@ -1468,6 +1478,7 @@ pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: u32, mode: mode_t)
14681478
.BUSY => return error.DeviceBusy,
14691479
.OPNOTSUPP => return error.FileLocksNotSupported,
14701480
.AGAIN => return error.WouldBlock,
1481+
.TXTBSY => return error.FileBusy,
14711482
else => |err| return unexpectedErrno(err),
14721483
}
14731484
}
@@ -4577,7 +4588,8 @@ pub const FlockError = error{
45774588
FileLocksNotSupported,
45784589
} || 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.
45814593
pub fn flock(fd: fd_t, operation: i32) FlockError!void {
45824594
while (true) {
45834595
const rc = system.flock(fd, operation);
@@ -4650,6 +4662,7 @@ pub fn realpathZ(pathname: [*:0]const u8, out_buffer: *[MAX_PATH_BYTES]u8) RealP
46504662
const fd = openZ(pathname, flags, 0) catch |err| switch (err) {
46514663
error.FileLocksNotSupported => unreachable,
46524664
error.WouldBlock => unreachable,
4665+
error.FileBusy => unreachable, // not asking for write permissions
46534666
else => |e| return e,
46544667
};
46554668
defer close(fd);

lib/std/zig/system/NativeTargetInfo.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ fn detectAbiAndDynamicLinker(
365365
error.PipeBusy => unreachable,
366366
error.FileLocksNotSupported => unreachable,
367367
error.WouldBlock => unreachable,
368+
error.FileBusy => unreachable, // opened without write permissions
368369

369370
error.IsDir,
370371
error.NotDir,

0 commit comments

Comments
 (0)