authorgravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 06:28:48 -08:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2020-12-15 06:28:48 -08:00
log58e0dbf66b03395592a5f0c5acde0dfdf05a7c94
tree1717034d74e3138a9b13d5aaa300c5967b9840a5
parenta2001cba235773437536924a2381126769477d4c

fetch: http: look for hash in version field and dont dl again if valid


2 files changed, 29 insertions(+), 13 deletions(-)

src/cmd_fetch.zig+29-11
......@@ -86,18 +86,18 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
8686 // no op
8787 },
8888 .git => blk: {
89 if (!try u.does_file_exist(p)) {
90 _ = try d.type.pull(d.path, p);
89 if (!try u.does_folder_exist(p)) {
90 try d.type.pull(d.path, p);
9191 }
9292 else {
93 _ = try d.type.update(p, d.path);
93 try d.type.update(p, d.path);
9494 }
9595 if (d.version.len > 0) {
9696 const iter = &std.mem.split(d.version, "-");
9797 const v_type_s = iter.next().?;
9898 if (std.meta.stringToEnum(u.GitVersionType, v_type_s)) |v_type| {
9999 const ref = iter.rest();
100 if (try u.does_file_exist(pv)) {
100 if (try u.does_folder_exist(pv)) {
101101 if (v_type == .branch) {
102102 try d.type.update(p, d.path);
103103 }
......@@ -109,7 +109,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
109109 } else {
110110 _ = try u.run_cmd(p, &[_][]const u8{"git", "checkout", "-"});
111111 }
112 _ = try u.run_cmd(null, &[_][]const u8{"git", "clone", d.path, pv});
112 try d.type.pull(d.path, pv);
113113 _ = try u.run_cmd(pv, &[_][]const u8{"git", "checkout", ref});
114114 if (v_type != .branch) {
115115 const pvd = try u.open_dir_absolute(pv);
......@@ -123,19 +123,37 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
123123 }
124124 },
125125 .hg => {
126 if (!try u.does_file_exist(p)) {
127 _ = try d.type.pull(d.path, p);
126 if (!try u.does_folder_exist(p)) {
127 try d.type.pull(d.path, p);
128128 }
129129 else {
130 _ = try d.type.update(p, d.path);
130 try d.type.update(p, d.path);
131131 }
132132 },
133 .http => {
133 .http => blk: {
134 if (try u.does_folder_exist(pv)) {
135 moddir = pv;
136 break :blk;
137 }
134138 const file_name = try u.last(try u.split(d.path, "/"));
135 if (try u.does_file_exist(p)) {
139 if (d.version.len > 0) {
140 const file_path = try std.fs.path.join(gpa, &[_][]const u8{pv, file_name});
141 try d.type.pull(d.path, pv);
142 if (try u.validate_hash(try u.last(try u.split(pv, "/")), file_path)) {
143 try std.fs.deleteFileAbsolute(file_path);
144 moddir = pv;
145 break :blk;
146 }
147 try u.rm_recv(pv);
148 u.assert(false, "{} does not match hash {}", .{d.path, d.version});
149 break :blk;
150 }
151 if (try u.does_folder_exist(p)) {
136152 try u.rm_recv(p);
137153 }
138 _ = try d.type.pull(d.path, p);
154 const file_path = try std.fs.path.join(gpa, &[_][]const u8{p, file_name});
155 try d.type.pull(d.path, p);
156 try std.fs.deleteFileAbsolute(file_path);
139157 },
140158 }
141159 switch (d.type) {
src/util/dep_type.zig-2
......@@ -27,7 +27,6 @@ pub const DepType = enum {
2727 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];
2828 if (std.mem.endsWith(u8, f, ".zip")) {
2929 _ = try u.run_cmd(dpath, &[_][]const u8{"unzip", f, "-d", "."});
30 try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
3130 }
3231 if (
3332 std.mem.endsWith(u8, f, ".tar")
......@@ -36,7 +35,6 @@ pub const DepType = enum {
3635 or std.mem.endsWith(u8, f, ".tar.zst")
3736 ) {
3837 _ = try u.run_cmd(dpath, &[_][]const u8{"tar", "-xf", f, "-C", "."});
39 try std.fs.deleteFileAbsolute(try std.fs.path.join(gpa, &[_][]const u8{dpath, f}));
4038 }
4139 },
4240 }