Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src-self-hosted/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,21 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
if (fmt.seen.exists(real_path)) return;
try fmt.seen.put(real_path);

const source_file = fs.cwd().openFile(real_path, .{}) catch |err| switch (err) {
error.IsDir, error.AccessDenied => {
const source_file = fs.cwd().openFile(real_path, .{}) catch |err| {
std.debug.warn("unable to open '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
};
defer source_file.close();

const stat = source_file.stat() catch |err| {
std.debug.warn("unable to stat '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
};

const source_code = source_file.readAllAlloc(fmt.gpa, stat.size, max_src_size) catch |err| switch (err) {
error.IsDir => {
var dir = try fs.cwd().openDir(file_path, .{ .iterate = true });
defer dir.close();

Expand All @@ -700,24 +713,11 @@ fn fmtPath(fmt: *Fmt, file_path: []const u8, check_mode: bool) FmtError!void {
return;
},
else => {
std.debug.warn("unable to open '{}': {}\n", .{ file_path, err });
std.debug.warn("unable to read '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
},
};
defer source_file.close();

const stat = source_file.stat() catch |err| {
std.debug.warn("unable to stat '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
};

const source_code = source_file.readAllAlloc(fmt.gpa, stat.size, max_src_size) catch |err| {
std.debug.warn("unable to read '{}': {}\n", .{ file_path, err });
fmt.any_error = true;
return;
};
defer fmt.gpa.free(source_code);

const tree = std.zig.parse(fmt.gpa, source_code) catch |err| {
Expand Down