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 {...@@ -35,12 +35,12 @@ fn detect_pkgname(def: []const u8) ![]const u8 {
3535
36fn detct_mainfile(def: []const u8) ![]const u8 {36fn detct_mainfile(def: []const u8) ![]const u8 {
37 if (def.len > 0) {37 if (def.len > 0) {
38 if (u.does_file_exist(def)) {38 if (try u.does_file_exist(def)) {
39 if (std.mem.endsWith(u8, def, ".zig")) {39 if (std.mem.endsWith(u8, def, ".zig")) {
40 return def;40 return def;
41 }41 }
42 }42 }
43 }43 }
44 std.debug.assert(u.does_file_exist("./src/main.zig"));44 std.debug.assert(try u.does_file_exist("./src/main.zig"));
45 return "src/main.zig";45 return "src/main.zig";
46}46}
src/util/funcs.zig+3-3
...@@ -40,11 +40,11 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {...@@ -40,11 +40,11 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {
40 return in;40 return in;
41}41}
4242
43pub fn does_file_exist(fpath: []const u8) bool {43pub fn does_file_exist(fpath: []const u8) !bool {
44 const abs_path = std.fs.realpathAlloc(gpa, fpath) catch unreachable;44 const abs_path = try std.fs.realpathAlloc(gpa, fpath);
45 const file = std.fs.openFileAbsolute(abs_path, .{}) catch |e| switch (e) {45 const file = std.fs.openFileAbsolute(abs_path, .{}) catch |e| switch (e) {
46 error.FileNotFound => return false,46 error.FileNotFound => return false,
47 else => unreachable,47 else => return e,
48 };48 };
49 file.close();49 file.close();
50 return true;50 return true;