authorgravatar for ed.dean515@gmail.comDrDeano <ed.dean515@gmail.com> 2020-06-20 15:12:52+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-20 17:25:12-04:00
logbc0ca73887d12ff71e12ad473bab22631a29b1aa
treef16863c83f28d2a70e4d8bec797dab222b62eaad
parent5229f6ec68708c3e66393a50ad9f9032ee7f4257

Moved the check for formatting a directory

The original check for a directory was for the `readAllAlloc` so move the check from open to read. This in turn fixes the fmt step in the build script for directories.

1 files changed, 16 insertions(+), 16 deletions(-)

src-self-hosted/main.zig+16-16
......@@ -684,8 +684,21 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
684684 if (fmt.seen.exists(real_path)) return;
685685 try fmt.seen.put(real_path);
686686
687 const source_file = fs.cwd().openFile(real_path, .{}) catch |err| switch (err) {
688 error.IsDir, error.AccessDenied => {
687 const source_file = fs.cwd().openFile(real_path, .{}) catch |err| {
688 std.debug.warn("unable to open '{}': {}\n", .{ file_path, err });
689 fmt.any_error = true;
690 return;
691 };
692 defer source_file.close();
693
694 const stat = source_file.stat() catch |err| {
695 std.debug.warn("unable to stat '{}': {}\n", .{ file_path, err });
696 fmt.any_error = true;
697 return;
698 };
699
700 const source_code = source_file.readAllAlloc(fmt.gpa, stat.size, max_src_size) catch |err| switch (err) {
701 error.IsDir => {
689702 var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
690703 defer dir.close();
691704
......@@ -700,24 +713,11 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
700713 return;
701714 },
702715 else => {
703 std.debug.warn("unable to open '{}': {}\n", .{ file_path, err });
716 std.debug.warn("unable to read '{}': {}\n", .{ file_path, err });
704717 fmt.any_error = true;
705718 return;
706719 },
707720 };
708 defer source_file.close();
709
710 const stat = source_file.stat() catch |err| {
711 std.debug.warn("unable to stat '{}': {}\n", .{ file_path, err });
712 fmt.any_error = true;
713 return;
714 };
715
716 const source_code = source_file.readAllAlloc(fmt.gpa, stat.size, max_src_size) catch |err| {
717 std.debug.warn("unable to read '{}': {}\n", .{ file_path, err });
718 fmt.any_error = true;
719 return;
720 };
721721 defer fmt.gpa.free(source_code);
722722
723723 const tree = std.zig.parse(fmt.gpa, source_code) catch |err| {