authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-14 14:03:04 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-11-14 14:03:04 -08:00
log575a2e7e6cd372d335e4227a0bd15cc416e78cbf
treed2f26209608b96e7e3a27c6f588accf5608ee846
parent72105b7cc5052fa63e544b9f76902c083523349f

zig: does_file_exist should return the error it doesnt handle


2 files changed, 5 insertions(+), 5 deletions(-)

src/cmd_init.zig+2-2
......@@ -35,12 +35,12 @@ fn detect_pkgname(def: []const u8) ![]const u8 {
3535
3636fn detct_mainfile(def: []const u8) ![]const u8 {
3737 if (def.len > 0) {
38 if (u.does_file_exist(def)) {
38 if (try u.does_file_exist(def)) {
3939 if (std.mem.endsWith(u8, def, ".zig")) {
4040 return def;
4141 }
4242 }
4343 }
44 std.debug.assert(u.does_file_exist("./src/main.zig"));
44 std.debug.assert(try u.does_file_exist("./src/main.zig"));
4545 return "src/main.zig";
4646}
src/util/funcs.zig+3-3
......@@ -40,11 +40,11 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {
4040 return in;
4141}
4242
43pub fn does_file_exist(fpath: []const u8) bool {
44 const abs_path = std.fs.realpathAlloc(gpa, fpath) catch unreachable;
43pub fn does_file_exist(fpath: []const u8) !bool {
44 const abs_path = try std.fs.realpathAlloc(gpa, fpath);
4545 const file = std.fs.openFileAbsolute(abs_path, .{}) catch |e| switch (e) {
4646 error.FileNotFound => return false,
47 else => unreachable,
47 else => return e,
4848 };
4949 file.close();
5050 return true;