diff --git a/src/cmd/fetch.zig b/src/cmd/fetch.zig index 08233f0ba0eec2b43d78881ac408bbb19eaaf90d..6713694525fe1437106ab58e56bb5d0acdcf6118 100644 --- a/src/cmd/fetch.zig +++ b/src/cmd/fetch.zig @@ -1,6 +1,7 @@ const std = @import("std"); const string = []const u8; const ansi = @import("ansi"); +const extras = @import("extras"); const zigmod = @import("../lib.zig"); const u = @import("./../util/index.zig"); @@ -201,7 +202,7 @@ const DiffChange = struct { fn diff_lockfile(alloc: std.mem.Allocator) !void { const max = std.math.maxInt(usize); - if (try u.does_folder_exist(".git")) { + if (try extras.doesFolderExist(null, ".git")) { const result = try u.run_cmd_raw(alloc, null, &.{ "git", "diff", "zigmod.lock" }); var stdout = std.io.fixedBufferStream(result.stdout); const r = stdout.reader(); diff --git a/src/cmd/init.zig b/src/cmd/init.zig index e215648382dae8cdff24b58ca9004919cb43c7d7..94048925b950df2af2dafc7106ba852810c84e1c 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -135,7 +135,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void { } // ask about .gitignore - if (try u.does_folder_exist(".git")) { + if (try extras.doesFolderExist(null, ".git")) { const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa); if (do) { const exists = try extras.doesFileExist(null, ".gitignore"); @@ -155,7 +155,7 @@ pub fn execute(self_name: []const u8, args: [][]u8) !void { } // ask about .gitattributes - if (try u.does_folder_exist(".git")) { + if (try extras.doesFolderExist(null, ".git")) { const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa); if (do) { const exists = try extras.doesFileExist(null, ".gitattributes"); diff --git a/src/common.zig b/src/common.zig index c1765c0676d6c6749cbca8291588c382a92c31f0..ca7912539c06ff9a836a36edbe5e9c5c2b8a4c87 100644 --- a/src/common.zig +++ b/src/common.zig @@ -136,7 +136,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! u.fail("fetch: git: version type '{s}' is invalid.", .{vtype}); }, }; - if (try u.does_folder_exist(pv)) { + if (try extras.doesFolderExist(null, pv)) { if (vers.id == .branch) { if (options.update) { try d.type.update(options.alloc, pv, d.path); @@ -158,7 +158,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! try setTreeReadOnly(pvd, options.alloc); return pv; } - if (!try u.does_folder_exist(p)) { + if (!try extras.doesFolderExist(null, p)) { try d.type.pull(options.alloc, d.path, p); } else { if (options.update) { @@ -168,7 +168,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! return p; }, .hg => { - if (!try u.does_folder_exist(p)) { + if (!try extras.doesFolderExist(null, p)) { try d.type.pull(options.alloc, d.path, p); } else { if (options.update) { @@ -178,12 +178,12 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! return p; }, .http => { - if (try u.does_folder_exist(pv)) { + if (try extras.doesFolderExist(null, pv)) { return pv; } const file_name = try u.last(try u.split(options.alloc, d.path, "/")); if (d.version.len > 0) { - if (try u.does_folder_exist(pv)) { + if (try extras.doesFolderExist(null, pv)) { return pv; } const file_path = try std.fs.path.join(options.alloc, &.{ pv, file_name }); @@ -199,7 +199,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) ! u.fail("{s} does not match hash {s}", .{ d.path, d.version }); return p; } - if (try u.does_folder_exist(p)) { + if (try extras.doesFolderExist(null, p)) { try std.fs.cwd().deleteTree(p); } const file_path = try std.fs.path.resolve(options.alloc, &.{ p, file_name }); diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 11f6e007bb2b1cd38511945736ef621f37fbf00f..97b73547cfc6fdedd58a769dbc834e08188bffdb 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -46,20 +46,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string { return list.toOwnedSlice(); } -pub fn does_folder_exist(fpath: string) !bool { - const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) { - error.FileNotFound => return false, - error.IsDir => return true, - else => |ee| return ee, - }; - defer file.close(); - const s = try file.stat(); - if (s.kind != .directory) { - return false; - } - return true; -} - pub fn trim_suffix(in: string, suffix: string) string { if (std.mem.endsWith(u8, in, suffix)) { return in[0 .. in.len - suffix.len];