| ... | @@ -684,8 +684,21 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { | ... | @@ -684,8 +684,21 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 684 | if (fmt.seen.exists(real_path)) return; | 684 | if (fmt.seen.exists(real_path)) return; |
| 685 | try fmt.seen.put(real_path); | 685 | try fmt.seen.put(real_path); |
| 686 | | 686 | |
| 687 | const source_file = fs.cwd().openFile(real_path, .{}) catch |err| switch (err) { | 687 | const source_file = fs.cwd().openFile(real_path, .{}) catch |err| { |
| 688 | error.IsDir, error.AccessDenied => { | 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 => { |
| 689 | var dir = try fs.cwd().openDir(file_path, .{ .iterate = true }); | 702 | var dir = try fs.cwd().openDir(file_path, .{ .iterate = true }); |
| 690 | defer dir.close(); | 703 | defer dir.close(); |
| 691 | | 704 | |
| ... | @@ -700,24 +713,11 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { | ... | @@ -700,24 +713,11 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 700 | return; | 713 | return; |
| 701 | }, | 714 | }, |
| 702 | else => { | 715 | else => { |
| 703 | std.debug.warn("unable to open '{}': {}\n", .{ file_path, err }); | 716 | std.debug.warn("unable to read '{}': {}\n", .{ file_path, err }); |
| 704 | fmt.any_error = true; | 717 | fmt.any_error = true; |
| 705 | return; | 718 | return; |
| 706 | }, | 719 | }, |
| 707 | }; | 720 | }; |
| 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 | }; | | |
| 721 | defer fmt.gpa.free(source_code); | 721 | defer fmt.gpa.free(source_code); |
| 722 | | 722 | |
| 723 | const tree = std.zig.parse(fmt.gpa, source_code) catch |err| { | 723 | const tree = std.zig.parse(fmt.gpa, source_code) catch |err| { |