| author | |
| committer | |
| log | 67caed05c15bee558beb29dd5f33d38cac874e89 |
| tree | ca7e3a29b230ff2a9a7440db0f9c94d70a353bb3 |
| parent | d2169e0ca9f2477017df633e2018d95986c696bb |
5 files changed, 15 insertions(+), 22 deletions(-)
src/cmd/aquila/install.zig+2-1| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const gpa = std.heap.c_allocator; |
| 4 | 4 | const knownfolders = @import("known-folders"); |
| 5 | const extras = @import("extras"); | |
| 5 | 6 | |
| 6 | 7 | const zigmod = @import("../../lib.zig"); |
| 7 | 8 | const u = @import("./../../util/index.zig"); |
| ... | ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { |
| 12 | 13 | const homepath = home.?; |
| 13 | 14 | const homedir = try std.fs.cwd().openDir(homepath, .{}); |
| 14 | 15 | |
| 15 | if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { | |
| 16 | if (!(try extras.doesFileExist(homedir, "zigmod.yml"))) { | |
| 16 | 17 | const f = try homedir.createFile("zigmod.yml", .{}); |
| 17 | 18 | defer f.close(); |
| 18 | 19 | const w = f.writer(); |
src/cmd/aquila/update.zig+2-1| ... | ... | @@ -2,6 +2,7 @@ const std = @import("std"); |
| 2 | 2 | const string = []const u8; |
| 3 | 3 | const gpa = std.heap.c_allocator; |
| 4 | 4 | const knownfolders = @import("known-folders"); |
| 5 | const extras = @import("extras"); | |
| 5 | 6 | |
| 6 | 7 | const zigmod = @import("../../lib.zig"); |
| 7 | 8 | const u = @import("./../../util/index.zig"); |
| ... | ... | @@ -12,7 +13,7 @@ pub fn execute(args: [][]u8) !void { |
| 12 | 13 | const homepath = home.?; |
| 13 | 14 | const homedir = try std.fs.cwd().openDir(homepath, .{}); |
| 14 | 15 | |
| 15 | if (!(try u.does_file_exist(homedir, "zigmod.yml"))) { | |
| 16 | if (!(try extras.doesFileExist(homedir, "zigmod.yml"))) { | |
| 16 | 17 | const f = try homedir.createFile("zigmod.yml", .{}); |
| 17 | 18 | defer f.close(); |
| 18 | 19 | const w = f.writer(); |
src/cmd/init.zig+5-4| ... | ... | @@ -6,6 +6,7 @@ const detectlicense = @import("detect-license"); |
| 6 | 6 | const knownfolders = @import("known-folders"); |
| 7 | 7 | const ini = @import("ini"); |
| 8 | 8 | const time = @import("time"); |
| 9 | const extras = @import("extras"); | |
| 9 | 10 | |
| 10 | 11 | const u = @import("./../util/index.zig"); |
| 11 | 12 | |
| ... | ... | @@ -72,7 +73,7 @@ pub fn execute(args: [][]u8) !void { |
| 72 | 73 | } |
| 73 | 74 | |
| 74 | 75 | // ask about LICENSE |
| 75 | if (!(try u.does_file_exist(null, "LICENSE"))) { | |
| 76 | if (!(try extras.doesFileExist(null, "LICENSE"))) { | |
| 76 | 77 | if (detectlicense.licenses.find(license)) |text| { |
| 77 | 78 | if (try inquirer.forConfirm(stdout, stdin, "It appears you don't have a LICENSE file defined, would you like init to add it for you?", gpa)) { |
| 78 | 79 | var realtext = text; |
| ... | ... | @@ -134,7 +135,7 @@ pub fn execute(args: [][]u8) !void { |
| 134 | 135 | if (try u.does_folder_exist(".git")) { |
| 135 | 136 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa); |
| 136 | 137 | if (do) { |
| 137 | const exists = try u.does_file_exist(null, ".gitignore"); | |
| 138 | const exists = try extras.doesFileExist(null, ".gitignore"); | |
| 138 | 139 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .mode = .read_write }) else cwd.createFile(".gitignore", .{})); |
| 139 | 140 | defer file.close(); |
| 140 | 141 | const len = try file.getEndPos(); |
| ... | ... | @@ -153,7 +154,7 @@ pub fn execute(args: [][]u8) !void { |
| 153 | 154 | if (try u.does_folder_exist(".git")) { |
| 154 | 155 | const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa); |
| 155 | 156 | if (do) { |
| 156 | const exists = try u.does_file_exist(null, ".gitattributes"); | |
| 157 | const exists = try extras.doesFileExist(null, ".gitattributes"); | |
| 157 | 158 | const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .mode = .read_write }) else cwd.createFile(".gitattributes", .{})); |
| 158 | 159 | defer file.close(); |
| 159 | 160 | const len = try file.getEndPos(); |
| ... | ... | @@ -188,7 +189,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry: |
| 188 | 189 | |
| 189 | 190 | fn guessCopyrightName() !?string { |
| 190 | 191 | const home = (try knownfolders.open(gpa, .home, .{})).?; |
| 191 | if (!(try u.does_file_exist(home, ".gitconfig"))) return null; | |
| 192 | if (!(try extras.doesFileExist(home, ".gitconfig"))) return null; | |
| 192 | 193 | const file = try home.openFile(".gitconfig", .{}); |
| 193 | 194 | const content = try file.reader().readAllAlloc(gpa, 1024 * 1024); |
| 194 | 195 | var iniO = try ini.parseIntoMap(content, gpa); |
src/common.zig+1-1| ... | ... | @@ -346,7 +346,7 @@ pub fn add_files_package(alloc: std.mem.Allocator, cachepath: string, pkg_name: |
| 346 | 346 | pub fn parse_lockfile(alloc: std.mem.Allocator, dir: std.fs.Dir) ![]const [4]string { |
| 347 | 347 | var list = std.ArrayList([4]string).init(alloc); |
| 348 | 348 | const max = std.math.maxInt(usize); |
| 349 | if (!try u.does_file_exist(dir, "zigmod.lock")) return &[_][4]string{}; | |
| 349 | if (!try extras.doesFileExist(dir, "zigmod.lock")) return &[_][4]string{}; | |
| 350 | 350 | const f = try dir.openFile("zigmod.lock", .{}); |
| 351 | 351 | const r = f.reader(); |
| 352 | 352 | var i: usize = 0; |
src/util/funcs.zig+5-15| ... | ... | @@ -45,16 +45,6 @@ pub fn split(alloc: std.mem.Allocator, in: string, delim: string) ![]string { |
| 45 | 45 | return list.toOwnedSlice(); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool { | |
| 49 | const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) { | |
| 50 | error.FileNotFound => return false, | |
| 51 | error.IsDir => return true, | |
| 52 | else => return e, | |
| 53 | }; | |
| 54 | defer file.close(); | |
| 55 | return true; | |
| 56 | } | |
| 57 | ||
| 58 | 48 | pub fn does_folder_exist(fpath: string) !bool { |
| 59 | 49 | const file = std.fs.cwd().openFile(fpath, .{}) catch |e| switch (e) { |
| 60 | 50 | error.FileNotFound => return false, |
| ... | ... | @@ -243,7 +233,7 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! |
| 243 | 233 | return override; |
| 244 | 234 | } |
| 245 | 235 | const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{}); |
| 246 | if (!(try does_file_exist(dirO, "build.zig"))) { | |
| 236 | if (!(try extras.doesFileExist(dirO, "build.zig"))) { | |
| 247 | 237 | return error.NoBuildZig; |
| 248 | 238 | } |
| 249 | 239 | const dpath = try std.fs.realpathAlloc(alloc, try std.fs.path.join(alloc, &.{ dir, "build.zig" })); |
| ... | ... | @@ -256,20 +246,20 @@ pub fn detect_pkgname(alloc: std.mem.Allocator, override: string, dir: string) ! |
| 256 | 246 | |
| 257 | 247 | pub fn detct_mainfile(alloc: std.mem.Allocator, override: string, dir: ?std.fs.Dir, name: string) !string { |
| 258 | 248 | if (override.len > 0) { |
| 259 | if (try does_file_exist(dir, override)) { | |
| 249 | if (try extras.doesFileExist(dir, override)) { | |
| 260 | 250 | if (std.mem.endsWith(u8, override, ".zig")) { |
| 261 | 251 | return override; |
| 262 | 252 | } |
| 263 | 253 | } |
| 264 | 254 | } |
| 265 | 255 | const namedotzig = try std.mem.concat(alloc, u8, &.{ name, ".zig" }); |
| 266 | if (try does_file_exist(dir, namedotzig)) { | |
| 256 | if (try extras.doesFileExist(dir, namedotzig)) { | |
| 267 | 257 | return namedotzig; |
| 268 | 258 | } |
| 269 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { | |
| 259 | if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "lib.zig" }))) { | |
| 270 | 260 | return "src/lib.zig"; |
| 271 | 261 | } |
| 272 | if (try does_file_exist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { | |
| 262 | if (try extras.doesFileExist(dir, try std.fs.path.join(alloc, &.{ "src", "main.zig" }))) { | |
| 273 | 263 | return "src/main.zig"; |
| 274 | 264 | } |
| 275 | 265 | return error.CantFindMain; |