authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:34:33 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:34:33 -07:00
log5eeb1f37ad0f488b2c9b615b9590650ef4fd0f82
tree1cd11fab9a87ffefa02f070c29de5e7aa58ae571
parente0e95bedc45c574fef385e7f6a7a2253d1614108

fix order of util.does_file_exist signature


3 files changed, 10 insertions(+), 10 deletions(-)

src/cmd/aquila/install.zig+1-1
...@@ -13,7 +13,7 @@ pub fn execute(args: [][]u8) !void {...@@ -13,7 +13,7 @@ pub fn execute(args: [][]u8) !void {
13 const homepath = home.?;13 const homepath = home.?;
14 const homedir = try std.fs.cwd().openDir(homepath, .{});14 const homedir = try std.fs.cwd().openDir(homepath, .{});
1515
16 if (!(try u.does_file_exist("zig.mod", homedir))) {16 if (!(try u.does_file_exist(homedir, "zig.mod"))) {
17 const f = try homedir.createFile("zig.mod", .{});17 const f = try homedir.createFile("zig.mod", .{});
18 defer f.close();18 defer f.close();
19 const w = f.writer();19 const w = f.writer();
src/cmd/init.zig+3-3
...@@ -78,7 +78,7 @@ pub fn execute(args: [][]u8) !void {...@@ -78,7 +78,7 @@ pub fn execute(args: [][]u8) !void {
78 if (try u.does_folder_exist(".git")) {78 if (try u.does_folder_exist(".git")) {
79 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);79 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
80 if (do) {80 if (do) {
81 const exists = try u.does_file_exist(".gitignore", null);81 const exists = try u.does_file_exist(null, ".gitignore");
82 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));82 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));
83 defer file.close();83 defer file.close();
84 const len = try file.getEndPos();84 const len = try file.getEndPos();
...@@ -94,7 +94,7 @@ pub fn execute(args: [][]u8) !void {...@@ -94,7 +94,7 @@ pub fn execute(args: [][]u8) !void {
94 }94 }
9595
96 // ask about LICENSE96 // ask about LICENSE
97 if (!(try u.does_file_exist("LICENSE", null))) {97 if (!(try u.does_file_exist(null, "LICENSE"))) {
98 if (detectlicense.licenses.find(license)) |text| {98 if (detectlicense.licenses.find(license)) |text| {
99 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)) {99 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)) {
100 var realtext = text;100 var realtext = text;
...@@ -141,7 +141,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry:...@@ -141,7 +141,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry:
141141
142fn guessCopyrightName() !?string {142fn guessCopyrightName() !?string {
143 const home = (try knownfolders.open(gpa, .home, .{})).?;143 const home = (try knownfolders.open(gpa, .home, .{})).?;
144 if (!(try u.does_file_exist(".gitconfig", home))) return null;144 if (!(try u.does_file_exist(home, ".gitconfig"))) return null;
145 const file = try home.openFile(".gitconfig", .{});145 const file = try home.openFile(".gitconfig", .{});
146 const content = try file.reader().readAllAlloc(gpa, 1024 * 1024);146 const content = try file.reader().readAllAlloc(gpa, 1024 * 1024);
147 var iniO = try ini.parseIntoMap(content, gpa);147 var iniO = try ini.parseIntoMap(content, gpa);
src/util/funcs.zig+6-6
...@@ -55,7 +55,7 @@ pub fn trim_prefix(in: string, prefix: string) string {...@@ -55,7 +55,7 @@ pub fn trim_prefix(in: string, prefix: string) string {
55 return in;55 return in;
56}56}
5757
58pub fn does_file_exist(fpath: string, dir: ?std.fs.Dir) !bool {58pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool {
59 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {59 const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) {
60 error.FileNotFound => return false,60 error.FileNotFound => return false,
61 error.IsDir => return true,61 error.IsDir => return true,
...@@ -263,7 +263,7 @@ pub fn detect_pkgname(override: string, dir: string) !string {...@@ -263,7 +263,7 @@ pub fn detect_pkgname(override: string, dir: string) !string {
263 return override;263 return override;
264 }264 }
265 const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{});265 const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{});
266 if (!(try does_file_exist("build.zig", dirO))) {266 if (!(try does_file_exist(dirO, "build.zig"))) {
267 return error.NoBuildZig;267 return error.NoBuildZig;
268 }268 }
269 const dpath = try std.fs.realpathAlloc(gpa, try std.mem.concat(gpa, u8, &.{ dir, "build.zig" }));269 const dpath = try std.fs.realpathAlloc(gpa, try std.mem.concat(gpa, u8, &.{ dir, "build.zig" }));
...@@ -276,20 +276,20 @@ pub fn detect_pkgname(override: string, dir: string) !string {...@@ -276,20 +276,20 @@ pub fn detect_pkgname(override: string, dir: string) !string {
276276
277pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string {277pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string {
278 if (override.len > 0) {278 if (override.len > 0) {
279 if (try does_file_exist(override, dir)) {279 if (try does_file_exist(dir, override)) {
280 if (std.mem.endsWith(u8, override, ".zig")) {280 if (std.mem.endsWith(u8, override, ".zig")) {
281 return override;281 return override;
282 }282 }
283 }283 }
284 }284 }
285 const namedotzig = try std.mem.concat(gpa, u8, &.{ name, ".zig" });285 const namedotzig = try std.mem.concat(gpa, u8, &.{ name, ".zig" });
286 if (try does_file_exist(namedotzig, dir)) {286 if (try does_file_exist(dir, namedotzig)) {
287 return namedotzig;287 return namedotzig;
288 }288 }
289 if (try does_file_exist(try std.fs.path.join(gpa, &.{ "src", "lib.zig" }), dir)) {289 if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "lib.zig" }))) {
290 return "src/lib.zig";290 return "src/lib.zig";
291 }291 }
292 if (try does_file_exist(try std.fs.path.join(gpa, &.{ "src", "main.zig" }), dir)) {292 if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "main.zig" }))) {
293 return "src/main.zig";293 return "src/main.zig";
294 }294 }
295 return error.CantFindMain;295 return error.CantFindMain;