| ... | ... | @@ -684,7 +684,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 684 | 684 | if (fmt.seen.exists(real_path)) return; |
| 685 | 685 | try fmt.seen.put(real_path); |
| 686 | 686 | |
| 687 | | const source_code = fs.cwd().readFileAlloc(fmt.gpa, real_path, max_src_size) catch |err| switch (err) { |
| 687 | const source_file = fs.cwd().openFile(real_path, .{}) catch |err| switch (err) { |
| 688 | 688 | error.IsDir, error.AccessDenied => { |
| 689 | 689 | var dir = try fs.cwd().openDir(file_path, .{ .iterate = true }); |
| 690 | 690 | defer dir.close(); |
| ... | ... | @@ -705,6 +705,13 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 705 | 705 | return; |
| 706 | 706 | }, |
| 707 | 707 | }; |
| 708 | defer source_file.close(); |
| 709 | |
| 710 | const source_code = source_file.reader().readAllAlloc(fmt.gpa, max_src_size) catch |err| { |
| 711 | std.debug.warn("unable to read '{}': {}\n", .{ file_path, err }); |
| 712 | fmt.any_error = true; |
| 713 | return; |
| 714 | }; |
| 708 | 715 | defer fmt.gpa.free(source_code); |
| 709 | 716 | |
| 710 | 717 | const tree = std.zig.parse(fmt.gpa, source_code) catch |err| { |
| ... | ... | @@ -729,7 +736,7 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void { |
| 729 | 736 | fmt.any_error = true; |
| 730 | 737 | } |
| 731 | 738 | } else { |
| 732 | | const baf = try io.BufferedAtomicFile.create(fmt.gpa, fs.cwd(), real_path, .{}); |
| 739 | const baf = try io.BufferedAtomicFile.create(fmt.gpa, fs.cwd(), real_path, .{ .mode = try source_file.mode() }); |
| 733 | 740 | defer baf.destroy(); |
| 734 | 741 | |
| 735 | 742 | const anything_changed = try std.zig.render(fmt.gpa, baf.stream(), tree); |