From 5eeb1f37ad0f488b2c9b615b9590650ef4fd0f82 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 28 Oct 2021 03:34:33 -0700 Subject: [PATCH] fix order of util.does_file_exist signature --- src/cmd/aquila/install.zig | 2 +- src/cmd/init.zig | 6 +++--- src/util/funcs.zig | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cmd/aquila/install.zig b/src/cmd/aquila/install.zig index eebc5d4659c7281018c400611ff5253c03ffc0f8..fafc644e286ee0e54bfc941dd8ed9595eec9916f 100644 --- a/src/cmd/aquila/install.zig +++ b/src/cmd/aquila/install.zig @@ -13,7 +13,7 @@ pub fn execute(args: [][]u8) !void { const homepath = home.?; const homedir = try std.fs.cwd().openDir(homepath, .{}); - if (!(try u.does_file_exist("zig.mod", homedir))) { + if (!(try u.does_file_exist(homedir, "zig.mod"))) { const f = try homedir.createFile("zig.mod", .{}); defer f.close(); const w = f.writer(); diff --git a/src/cmd/init.zig b/src/cmd/init.zig index 96a5d8487f01420e1778574badc40c36e8d20b80..cf85d528c113b1fbee33bd7c8d80fa9e32b8551b 100644 --- a/src/cmd/init.zig +++ b/src/cmd/init.zig @@ -78,7 +78,7 @@ pub fn execute(args: [][]u8) !void { if (try u.does_folder_exist(".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 u.does_file_exist(".gitignore", null); + const exists = try u.does_file_exist(null, ".gitignore"); const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{})); defer file.close(); const len = try file.getEndPos(); @@ -94,7 +94,7 @@ pub fn execute(args: [][]u8) !void { } // ask about LICENSE - if (!(try u.does_file_exist("LICENSE", null))) { + if (!(try u.does_file_exist(null, "LICENSE"))) { if (detectlicense.licenses.find(license)) |text| { 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)) { var realtext = text; @@ -141,7 +141,7 @@ pub fn writeLibManifest(w: std.fs.File.Writer, id: string, name: string, entry: fn guessCopyrightName() !?string { const home = (try knownfolders.open(gpa, .home, .{})).?; - if (!(try u.does_file_exist(".gitconfig", home))) return null; + if (!(try u.does_file_exist(home, ".gitconfig"))) return null; const file = try home.openFile(".gitconfig", .{}); const content = try file.reader().readAllAlloc(gpa, 1024 * 1024); var iniO = try ini.parseIntoMap(content, gpa); diff --git a/src/util/funcs.zig b/src/util/funcs.zig index 96def941d4b7c6e4fd1405c769e57c4bfe927dcf..630ec7f4b2c48b2c83f3ba0ae63c149c4db7639a 100644 --- a/src/util/funcs.zig +++ b/src/util/funcs.zig @@ -55,7 +55,7 @@ pub fn trim_prefix(in: string, prefix: string) string { return in; } -pub fn does_file_exist(fpath: string, dir: ?std.fs.Dir) !bool { +pub fn does_file_exist(dir: ?std.fs.Dir, fpath: string) !bool { const file = (dir orelse std.fs.cwd()).openFile(fpath, .{}) catch |e| switch (e) { error.FileNotFound => return false, error.IsDir => return true, @@ -263,7 +263,7 @@ pub fn detect_pkgname(override: string, dir: string) !string { return override; } const dirO = if (dir.len == 0) std.fs.cwd() else try std.fs.cwd().openDir(dir, .{}); - if (!(try does_file_exist("build.zig", dirO))) { + if (!(try does_file_exist(dirO, "build.zig"))) { return error.NoBuildZig; } 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 { pub fn detct_mainfile(override: string, dir: ?std.fs.Dir, name: string) !string { if (override.len > 0) { - if (try does_file_exist(override, dir)) { + if (try does_file_exist(dir, override)) { if (std.mem.endsWith(u8, override, ".zig")) { return override; } } } const namedotzig = try std.mem.concat(gpa, u8, &.{ name, ".zig" }); - if (try does_file_exist(namedotzig, dir)) { + if (try does_file_exist(dir, namedotzig)) { return namedotzig; } - if (try does_file_exist(try std.fs.path.join(gpa, &.{ "src", "lib.zig" }), dir)) { + if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "lib.zig" }))) { return "src/lib.zig"; } - if (try does_file_exist(try std.fs.path.join(gpa, &.{ "src", "main.zig" }), dir)) { + if (try does_file_exist(dir, try std.fs.path.join(gpa, &.{ "src", "main.zig" }))) { return "src/main.zig"; } return error.CantFindMain; -- 2.54.0