authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 06:23:46 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 06:23:46 -08:00
log111b88da9e3b4c4f5e1a3271f5befaa8abbf3146
treecaa1fa2b919dc52cd7930146dd232a38b4f3773c
parentc7d72c12f2c8e7a92e0a14d742c3a42755af8fb6

util: replace realpathalloc with openfile


1 files changed, 2 insertions(+), 7 deletions(-)

src/util/funcs.zig+2-7
...@@ -45,11 +45,7 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {...@@ -45,11 +45,7 @@ pub fn trim_prefix(in: []const u8, prefix: []const u8) []const u8 {
45}45}
4646
47pub fn does_file_exist(fpath: []const u8) !bool {47pub fn does_file_exist(fpath: []const u8) !bool {
48 const abs_path = std.fs.realpathAlloc(gpa, fpath) catch |e| switch (e) {48 const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) {
49 error.FileNotFound => return false,
50 else => return e,
51 };
52 const file = std.fs.openFileAbsolute(abs_path, .{}) catch |e| switch (e) {
53 error.FileNotFound => return false,49 error.FileNotFound => return false,
54 else => return e,50 else => return e,
55 };51 };
...@@ -58,11 +54,10 @@ pub fn does_file_exist(fpath: []const u8) !bool {...@@ -58,11 +54,10 @@ pub fn does_file_exist(fpath: []const u8) !bool {
58}54}
5955
60pub fn does_folder_exist(fpath: []const u8) !bool {56pub fn does_folder_exist(fpath: []const u8) !bool {
61 const abs_path = std.fs.realpathAlloc(gpa, fpath) catch |e| switch (e) {57 const file = try std.fs.cwd().openFile(abs_path, .{}) catch |e| switch (e) {
62 error.FileNotFound => return false,58 error.FileNotFound => return false,
63 else => return e,59 else => return e,
64 };60 };
65 const file = try std.fs.openFileAbsolute(abs_path, .{});
66 defer file.close();61 defer file.close();
67 const s = try file.stat();62 const s = try file.stat();
68 if (s.kind != .Directory) {63 if (s.kind != .Directory) {