diff --git a/src/cmd_fetch.zig b/src/cmd_fetch.zig index cac69e7bcc32076197a814ef56c6c05e6e223394..c87f0f651811afde2014dd81402e3f0c3066dfdd 100644 --- a/src/cmd_fetch.zig +++ b/src/cmd_fetch.zig @@ -86,18 +86,18 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { // no op }, .git => blk: { - if (!try u.does_file_exist(p)) { - _ = try d.type.pull(d.path, p); + if (!try u.does_folder_exist(p)) { + try d.type.pull(d.path, p); } else { - _ = try d.type.update(p, d.path); + try d.type.update(p, d.path); } if (d.version.len > 0) { const iter = &std.mem.split(d.version, "-"); const v_type_s = iter.next().?; if (std.meta.stringToEnum(u.GitVersionType, v_type_s)) |v_type| { const ref = iter.rest(); - if (try u.does_file_exist(pv)) { + if (try u.does_folder_exist(pv)) { if (v_type == .branch) { try d.type.update(p, d.path); } @@ -109,7 +109,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { } else { _ = try u.run_cmd(p, &[_][]const u8{"git", "checkout", "-"}); } - _ = try u.run_cmd(null, &[_][]const u8{"git", "clone", d.path, pv}); + try d.type.pull(d.path, pv); _ = try u.run_cmd(pv, &[_][]const u8{"git", "checkout", ref}); if (v_type != .branch) { const pvd = try u.open_dir_absolute(pv); @@ -123,19 +123,37 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module { } }, .hg => { - if (!try u.does_file_exist(p)) { - _ = try d.type.pull(d.path, p); + if (!try u.does_folder_exist(p)) { + try d.type.pull(d.path, p); } else { - _ = try d.type.update(p, d.path); + try d.type.update(p, d.path); } }, - .http => { + .http => blk: { + if (try u.does_folder_exist(pv)) { + moddir = pv; + break :blk; + } const file_name = try u.last(try u.split(d.path, "/")); - if (try u.does_file_exist(p)) { + if (d.version.len > 0) { + const file_path = try std.fs.path.join(gpa, &[_][]const u8{pv, file_name}); + try d.type.pull(d.path, pv); + if (try u.validate_hash(try u.last(try u.split(pv, "/")), file_path)) { + try std.fs.deleteFileAbsolute(file_path); + moddir = pv; + break :blk; + } + try u.rm_recv(pv); + u.assert(false, "{} does not match hash {}", .{d.path, d.version}); + break :blk; + } + if (try u.does_folder_exist(p)) { try u.rm_recv(p); } - _ = try d.type.pull(d.path, p); + const file_path = try std.fs.path.join(gpa, &[_][]const u8{p, file_name}); + try d.type.pull(d.path, p); + try std.fs.deleteFileAbsolute(file_path); }, } switch (d.type) { diff --git a/src/util/dep_type.zig b/src/util/dep_type.zig index 3a6af5ef371f4b8f328f033f942a8596f59e7c41..30f9f2eb900f290ae30cee1efa3013017ca4f1b7 100644 --- a/src/util/dep_type.zig +++ b/src/util/dep_type.zig @@ -27,7 +27,6 @@ pub const DepType = enum { const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..]; if (std.mem.endsWith(u8, f, ".zip")) { _ = try u.run_cmd(dpath, &[_][]const u8{"unzip", f, "-d", "."}); - try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f})); } if ( std.mem.endsWith(u8, f, ".tar") @@ -36,7 +35,6 @@ pub const DepType = enum { or std.mem.endsWith(u8, f, ".tar.zst") ) { _ = try u.run_cmd(dpath, &[_][]const u8{"tar", "-xf", f, "-C", "."}); - try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f})); } }, }