authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:55:43 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-28 03:55:43 -07:00
log2ffb060cfc4052fd3345536913d6fe15b4826b54
tree50503e08568595dc29dcbcc2b7be34045b5c3232
parenta8590c12cf668eb7becd862fc10cd8f77ad003a5

remove global allocator from u.validate_hash


2 files changed, 3 insertions(+), 3 deletions(-)

src/common.zig+1-1
......@@ -181,7 +181,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
181181 }
182182 const file_path = try std.fs.path.join(gpa, &.{ pv, file_name });
183183 try d.type.pull(gpa, d.path, pv);
184 if (try u.validate_hash(d.version, file_path)) {
184 if (try u.validate_hash(gpa, d.version, file_path)) {
185185 try std.fs.cwd().deleteFile(file_path);
186186 return pv;
187187 }
src/util/funcs.zig+2-2
......@@ -207,11 +207,11 @@ pub const HashFn = enum {
207207 sha512,
208208};
209209
210pub fn validate_hash(input: string, file_path: string) !bool {
210pub fn validate_hash(alloc: *std.mem.Allocator, input: string, file_path: string) !bool {
211211 const hash = parse_split(HashFn, "-").do(input) catch return false;
212212 const file = try std.fs.cwd().openFile(file_path, .{});
213213 defer file.close();
214 const data = try file.reader().readAllAlloc(gpa, gb);
214 const data = try file.reader().readAllAlloc(alloc, gb);
215215 const expected = hash.string;
216216 const actual = switch (hash.id) {
217217 .blake3 => try do_hash(std.crypto.hash.Blake3, data),