| author | |
| committer | |
| log | 5dc2db80554d2b50075ee7e9a9ee2ddf67e25a74 |
| tree | deadbb575daaa4822d15d7f3d43e46b19ab3945a |
| parent | 43b27d47c98e0ada00db828ddf410372c6ded66a |
| parent | 01f9cdd21a8f18941636c061a5985a040e4a4bcd |
| signature |
Fix `Dir.statFile` for WASI when linking libc2 files changed, 28 insertions(+), 14 deletions(-)
lib/std/fs.zig+10-14| ... | @@ -2653,21 +2653,17 @@ pub const Dir = struct { | ... | @@ -2653,21 +2653,17 @@ pub const Dir = struct { |
| 2653 | /// | 2653 | /// |
| 2654 | /// `sub_path` may be absolute, in which case `self` is ignored. | 2654 | /// `sub_path` may be absolute, in which case `self` is ignored. |
| 2655 | pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat { | 2655 | pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat { |
| 2656 | switch (builtin.os.tag) { | 2656 | if (builtin.os.tag == .windows) { |
| 2657 | .windows => { | 2657 | var file = try self.openFile(sub_path, .{}); |
| 2658 | var file = try self.openFile(sub_path, .{}); | 2658 | defer file.close(); |
| 2659 | defer file.close(); | 2659 | return file.stat(); |
| 2660 | return file.stat(); | 2660 | } |
| 2661 | }, | 2661 | if (builtin.os.tag == .wasi and !builtin.link_libc) { |
| 2662 | .wasi => { | 2662 | const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW); |
| 2663 | const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW); | 2663 | return Stat.fromSystem(st); |
| 2664 | return Stat.fromSystem(st); | ||
| 2665 | }, | ||
| 2666 | else => { | ||
| 2667 | const st = try os.fstatat(self.fd, sub_path, 0); | ||
| 2668 | return Stat.fromSystem(st); | ||
| 2669 | }, | ||
| 2670 | } | 2664 | } |
| 2665 | const st = try os.fstatat(self.fd, sub_path, 0); | ||
| 2666 | return Stat.fromSystem(st); | ||
| 2671 | } | 2667 | } |
| 2672 | 2668 | ||
| 2673 | const Permissions = File.Permissions; | 2669 | const Permissions = File.Permissions; |
lib/std/fs/test.zig+18| ... | @@ -569,6 +569,24 @@ test "readAllAlloc" { | ... | @@ -569,6 +569,24 @@ test "readAllAlloc" { |
| 569 | try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1)); | 569 | try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1)); |
| 570 | } | 570 | } |
| 571 | 571 | ||
| 572 | test "Dir.statFile" { | ||
| 573 | // TODO: Re-enable once https://github.com/ziglang/zig/issues/17034 is solved | ||
| 574 | if (builtin.os.tag == .linux and builtin.link_libc and builtin.abi == .gnu) return error.SkipZigTest; | ||
| 575 | |||
| 576 | try testWithAllSupportedPathTypes(struct { | ||
| 577 | fn impl(ctx: *TestContext) !void { | ||
| 578 | const test_file_name = try ctx.transformPath("test_file"); | ||
| 579 | |||
| 580 | try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name)); | ||
| 581 | |||
| 582 | try ctx.dir.writeFile(test_file_name, ""); | ||
| 583 | |||
| 584 | const stat = try ctx.dir.statFile(test_file_name); | ||
| 585 | try testing.expectEqual(File.Kind.file, stat.kind); | ||
| 586 | } | ||
| 587 | }.impl); | ||
| 588 | } | ||
| 589 | |||
| 572 | test "directory operations on files" { | 590 | test "directory operations on files" { |
| 573 | try testWithAllSupportedPathTypes(struct { | 591 | try testWithAllSupportedPathTypes(struct { |
| 574 | fn impl(ctx: *TestContext) !void { | 592 | fn impl(ctx: *TestContext) !void { |