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 {...@@ -86,18 +86,18 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
86 // no op86 // no op
87 },87 },
88 .git => blk: {88 .git => blk: {
89 if (!try u.does_file_exist(p)) {89 if (!try u.does_folder_exist(p)) {
90 _ = try d.type.pull(d.path, p);90 try d.type.pull(d.path, p);
91 }91 }
92 else {92 else {
93 _ = try d.type.update(p, d.path);93 try d.type.update(p, d.path);
94 }94 }
95 if (d.version.len > 0) {95 if (d.version.len > 0) {
96 const iter = &std.mem.split(d.version, "-");96 const iter = &std.mem.split(d.version, "-");
97 const v_type_s = iter.next().?;97 const v_type_s = iter.next().?;
98 if (std.meta.stringToEnum(u.GitVersionType, v_type_s)) |v_type| {98 if (std.meta.stringToEnum(u.GitVersionType, v_type_s)) |v_type| {
99 const ref = iter.rest();99 const ref = iter.rest();
100 if (try u.does_file_exist(pv)) {100 if (try u.does_folder_exist(pv)) {
101 if (v_type == .branch) {101 if (v_type == .branch) {
102 try d.type.update(p, d.path);102 try d.type.update(p, d.path);
103 }103 }
...@@ -109,7 +109,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -109,7 +109,7 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
109 } else {109 } else {
110 _ = try u.run_cmd(p, &[_][]const u8{"git", "checkout", "-"});110 _ = try u.run_cmd(p, &[_][]const u8{"git", "checkout", "-"});
111 }111 }
112 _ = try u.run_cmd(null, &[_][]const u8{"git", "clone", d.path, pv});112 try d.type.pull(d.path, pv);
113 _ = try u.run_cmd(pv, &[_][]const u8{"git", "checkout", ref});113 _ = try u.run_cmd(pv, &[_][]const u8{"git", "checkout", ref});
114 if (v_type != .branch) {114 if (v_type != .branch) {
115 const pvd = try u.open_dir_absolute(pv);115 const pvd = try u.open_dir_absolute(pv);
...@@ -123,19 +123,37 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {...@@ -123,19 +123,37 @@ fn fetch_deps(dir: []const u8, mpath: []const u8) anyerror!u.Module {
123 }123 }
124 },124 },
125 .hg => {125 .hg => {
126 if (!try u.does_file_exist(p)) {126 if (!try u.does_folder_exist(p)) {
127 _ = try d.type.pull(d.path, p);127 try d.type.pull(d.path, p);
128 }128 }
129 else {129 else {
130 _ = try d.type.update(p, d.path);130 try d.type.update(p, d.path);
131 }131 }
132 },132 },
133 .http => {133 .http => blk: {
134 if (try u.does_folder_exist(pv)) {
135 moddir = pv;
136 break :blk;
137 }
134 const file_name = try u.last(try u.split(d.path, "/"));138 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)) {
136 try u.rm_recv(p);152 try u.rm_recv(p);
137 }153 }
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);
139 },157 },
140 }158 }
141 switch (d.type) {159 switch (d.type) {
src/util/dep_type.zig-2
...@@ -27,7 +27,6 @@ pub const DepType = enum {...@@ -27,7 +27,6 @@ pub const DepType = enum {
27 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];27 const f = rpath[std.mem.lastIndexOf(u8, rpath, "/").?+1..];
28 if (std.mem.endsWith(u8, f, ".zip")) {28 if (std.mem.endsWith(u8, f, ".zip")) {
29 _ = try u.run_cmd(dpath, &[_][]const u8{"unzip", f, "-d", "."});29 _ = 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}));
31 }30 }
32 if (31 if (
33 std.mem.endsWith(u8, f, ".tar")32 std.mem.endsWith(u8, f, ".tar")
...@@ -36,7 +35,6 @@ pub const DepType = enum {...@@ -36,7 +35,6 @@ pub const DepType = enum {
36 or std.mem.endsWith(u8, f, ".tar.zst")35 or std.mem.endsWith(u8, f, ".tar.zst")
37 ) {36 ) {
38 _ = try u.run_cmd(dpath, &[_][]const u8{"tar", "-xf", f, "-C", "."});37 _ = 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}));
40 }38 }
41 },39 },
42 }40 }