authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-11 13:30:53 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-07-11 13:30:53 -07:00
log9cf5971c8e4d85e3bdce65496a183b85b53e423f
treee7f12b2b7995139bce24b2f0b3b481dbf03cadeb
parent98a31a81030224e13cb1977a8ef2792dfe478c8b

switch from `std.fs.Dir.realpathAlloc` to `std.fs.realpathAlloc`, cc #14

Thanks to @nfisher1226 for finding this fix :)

4 files changed, 7 insertions(+), 9 deletions(-)

src/cmd/init.zig+1-1
...@@ -7,7 +7,7 @@ const u = @import("./../util/index.zig");...@@ -7,7 +7,7 @@ const u = @import("./../util/index.zig");
7//7//
88
9pub fn execute(args: [][]u8) !void {9pub fn execute(args: [][]u8) !void {
10 const name = u.detect_pkgname(u.try_index([]const u8, args, 0, ""), null) catch |err| switch (err) {10 const name = u.detect_pkgname(u.try_index([]const u8, args, 0, ""), "") catch |err| switch (err) {
11 error.NoBuildZig => {11 error.NoBuildZig => {
12 u.assert(false, "init requires a build.zig file", .{});12 u.assert(false, "init requires a build.zig file", .{});
13 unreachable;13 unreachable;
src/common.zig+1-1
...@@ -229,7 +229,7 @@ pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8,...@@ -229,7 +229,7 @@ pub fn get_module_from_dep(d: *u.Dep, dir: []const u8, parent_name: []const u8,
229 return null;229 return null;
230 }230 }
231 const moddirO = try std.fs.cwd().openDir(moddir, .{});231 const moddirO = try std.fs.cwd().openDir(moddir, .{});
232 const tryname = try u.detect_pkgname("", moddirO);232 const tryname = try u.detect_pkgname("", moddir);
233 const trymain = u.detct_mainfile("", moddirO, tryname) catch |err| switch (err) {233 const trymain = u.detct_mainfile("", moddirO, tryname) catch |err| switch (err) {
234 error.CantFindMain => null,234 error.CantFindMain => null,
235 else => return err,235 else => return err,
src/util/funcs.zig+3-3
...@@ -265,14 +265,14 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const...@@ -265,14 +265,14 @@ pub fn slice(comptime T: type, input: []const T, from: usize, to: usize) []const
265 return input[f..t];265 return input[f..t];
266}266}
267267
268pub fn detect_pkgname(override: []const u8, dir: ?std.fs.Dir) ![]const u8 {268pub fn detect_pkgname(override: []const u8, dir: []const u8) ![]const u8 {
269 if (override.len > 0) {269 if (override.len > 0) {
270 return override;270 return override;
271 }271 }
272 if (!(try does_file_exist("build.zig", dir))) {272 if (!(try does_file_exist("build.zig", try std.fs.cwd().openDir(dir, .{})))) {
273 return error.NoBuildZig;273 return error.NoBuildZig;
274 }274 }
275 const dpath = try (dir orelse std.fs.cwd()).realpathAlloc(gpa, "build.zig");275 const dpath = try std.fs.realpathAlloc(gpa, try std.mem.concat(gpa, u8, &.{ dir, "build.zig" }));
276 const splitP = try split(dpath, std.fs.path.sep_str);276 const splitP = try split(dpath, std.fs.path.sep_str);
277 var name = splitP[splitP.len - 2];277 var name = splitP[splitP.len - 2];
278 name = trim_prefix(name, "zig-");278 name = trim_prefix(name, "zig-");
src/util/modfile.zig+2-4
...@@ -26,10 +26,8 @@ pub const ModFile = struct {...@@ -26,10 +26,8 @@ pub const ModFile = struct {
26 root_files: []const []const u8,26 root_files: []const []const u8,
27 files: []const []const u8,27 files: []const []const u8,
2828
29 pub fn init(alloc: *std.mem.Allocator, fpath: []const u8) !Self {29 pub fn init(alloc: *std.mem.Allocator, mpath: []const u8) !Self {
30 //30 const file = try std.fs.cwd().openFile(mpath, .{});
31 const mpath = try std.fs.realpathAlloc(alloc, fpath);
32 const file = try std.fs.openFileAbsolute(mpath, .{});
33 defer file.close();31 defer file.close();
34 const input = try file.reader().readAllAlloc(alloc, mb);32 const input = try file.reader().readAllAlloc(alloc, mb);
35 const doc = try yaml.parse(alloc, input);33 const doc = try yaml.parse(alloc, input);