| author | |
| committer | |
| log | f46008c1d8bce5dd8d1d0155fc3bd1c865870c79 |
| tree | 1a41a302fe607ac237ba08ba3e847d434c7fa6d7 |
| parent | f4c9e19bc3213c2bc7e03d7b06d7129882f39f6c |
`statFile` now only uses `os.fstatatWasi` when not linking libc, matching the pattern used throughout other `Dir` functions. This fixes the compilation error: `error: struct 'c.wasi.Stat' has no member named 'fromFilestat'` (which the added test would have failed with)2 files changed, 25 insertions(+), 14 deletions(-)
lib/std/fs.zig+10-14| ... | ... | @@ -2653,21 +2653,17 @@ pub const Dir = struct { |
| 2653 | 2653 | /// |
| 2654 | 2654 | /// `sub_path` may be absolute, in which case `self` is ignored. |
| 2655 | 2655 | pub fn statFile(self: Dir, sub_path: []const u8) StatFileError!Stat { |
| 2656 | switch (builtin.os.tag) { | |
| 2657 | .windows => { | |
| 2658 | var file = try self.openFile(sub_path, .{}); | |
| 2659 | defer file.close(); | |
| 2660 | return file.stat(); | |
| 2661 | }, | |
| 2662 | .wasi => { | |
| 2663 | const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW); | |
| 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 | }, | |
| 2656 | if (builtin.os.tag == .windows) { | |
| 2657 | var file = try self.openFile(sub_path, .{}); | |
| 2658 | defer file.close(); | |
| 2659 | return file.stat(); | |
| 2660 | } | |
| 2661 | if (builtin.os.tag == .wasi and !builtin.link_libc) { | |
| 2662 | const st = try os.fstatatWasi(self.fd, sub_path, os.wasi.LOOKUP_SYMLINK_FOLLOW); | |
| 2663 | return Stat.fromSystem(st); | |
| 2670 | 2664 | } |
| 2665 | const st = try os.fstatat(self.fd, sub_path, 0); | |
| 2666 | return Stat.fromSystem(st); | |
| 2671 | 2667 | } |
| 2672 | 2668 | |
| 2673 | 2669 | const Permissions = File.Permissions; |
lib/std/fs/test.zig+15| ... | ... | @@ -569,6 +569,21 @@ test "readAllAlloc" { |
| 569 | 569 | try testing.expectError(error.FileTooBig, file.readToEndAlloc(testing.allocator, write_buf.len - 1)); |
| 570 | 570 | } |
| 571 | 571 | |
| 572 | test "Dir.statFile" { | |
| 573 | try testWithAllSupportedPathTypes(struct { | |
| 574 | fn impl(ctx: *TestContext) !void { | |
| 575 | const test_file_name = try ctx.transformPath("test_file"); | |
| 576 | ||
| 577 | try testing.expectError(error.FileNotFound, ctx.dir.statFile(test_file_name)); | |
| 578 | ||
| 579 | try ctx.dir.writeFile(test_file_name, ""); | |
| 580 | ||
| 581 | const stat = try ctx.dir.statFile(test_file_name); | |
| 582 | try testing.expectEqual(File.Kind.file, stat.kind); | |
| 583 | } | |
| 584 | }.impl); | |
| 585 | } | |
| 586 | ||
| 572 | 587 | test "directory operations on files" { |
| 573 | 588 | try testWithAllSupportedPathTypes(struct { |
| 574 | 589 | fn impl(ctx: *TestContext) !void { |