mirror of
https://github.com/ziglang/zig.git
synced 2025-12-25 23:53:15 +00:00
Merge pull request #17029 from squeek502/wasi-statFile-libc
Fix `Dir.statFile` for WASI when linking libc
This commit is contained in:
commit
5dc2db8055
@ -2653,21 +2653,17 @@ pub const Dir = struct {
|
||||
///
|
||||
/// `sub_path` may be absolute, in which case `self` is ignored.
|
||||
pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat {
|
||||
switch (builtin.os.tag) {
|
||||
.windows => {
|
||||
var file = try self.openFile(sub_path, .{});
|
||||
defer file.close();
|
||||
return file.stat();
|
||||
},
|
||||
.wasi => {
|
||||
const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW);
|
||||
return Stat.fromSystem(st);
|
||||
},
|
||||
else => {
|
||||
const st = try os.fstatat(self.fd, sub_path, 0);
|
||||
return Stat.fromSystem(st);
|
||||
},
|
||||
if (builtin.os.tag == .windows) {
|
||||
var file = try self.openFile(sub_path, .{});
|
||||
defer file.close();
|
||||
return file.stat();
|
||||
}
|
||||
if (builtin.os.tag == .wasi and !builtin.link_libc) {
|
||||
const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW);
|
||||
return Stat.fromSystem(st);
|
||||
}
|
||||
const st = try os.fstatat(self.fd, sub_path, 0);
|
||||
return Stat.fromSystem(st);
|
||||
}
|
||||
|
||||
const Permissions = File.Permissions;
|
||||
|
||||
@ -569,6 +569,24 @@ test "readAllAlloc" {
|
||||
try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1));
|
||||
}
|
||||
|
||||
test "Dir.statFile" {
|
||||
// TODO: Re-enable once https://github.com/ziglang/zig/issues/17034 is solved
|
||||
if (builtin.os.tag == .linux and builtin.link_libc and builtin.abi == .gnu) return error.SkipZigTest;
|
||||
|
||||
try testWithAllSupportedPathTypes(struct {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
const test_file_name = try ctx.transformPath("test_file");
|
||||
|
||||
try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name));
|
||||
|
||||
try ctx.dir.writeFile(test_file_name, "");
|
||||
|
||||
const stat = try ctx.dir.statFile(test_file_name);
|
||||
try testing.expectEqual(File.Kind.file, stat.kind);
|
||||
}
|
||||
}.impl);
|
||||
}
|
||||
|
||||
test "directory operations on files" {
|
||||
try testWithAllSupportedPathTypes(struct {
|
||||
fn impl(ctx: *TestContext) !void {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user