Skip to content

Check the file type after open() in Dir.openFile() when using WASI #15824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/std/fs.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,11 @@ pub const Dir = struct {
w.RIGHT.FD_FILESTAT_SET_SIZE;
}
const fd = try os.openatWasi(self.fd, sub_path, 0x0, 0x0, fdflags, base, 0x0);
errdefer os.close(fd);
const fstat = try os.fstat(fd);
const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR;
if (is_dir) return error.IsDir;

return File{ .handle = fd };
}

Expand Down Expand Up @@ -1192,6 +1197,11 @@ pub const Dir = struct {
});
}
}
if (builtin.target.os.tag == .wasi) {
const fstat = try os.fstat(fd);
const is_dir = fstat.mode & os.S.IFMT == os.S.IFDIR;
if (is_dir) return error.IsDir;
}

if (has_flock_open_flags and flags.lock_nonblocking) {
var fl_flags = os.fcntl(fd, os.F.GETFL, 0) catch |err| switch (err) {
Expand Down