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) !...@@ -181,7 +181,7 @@ pub fn get_modpath(cachepath: string, d: zigmod.Dep, options: *CollectOptions) !
181 }181 }
182 const file_path = try std.fs.path.join(gpa, &.{ pv, file_name });182 const file_path = try std.fs.path.join(gpa, &.{ pv, file_name });
183 try d.type.pull(gpa, d.path, pv);183 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)) {
185 try std.fs.cwd().deleteFile(file_path);185 try std.fs.cwd().deleteFile(file_path);
186 return pv;186 return pv;
187 }187 }
src/util/funcs.zig+2-2
...@@ -207,11 +207,11 @@ pub const HashFn = enum {...@@ -207,11 +207,11 @@ pub const HashFn = enum {
207 sha512,207 sha512,
208};208};
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 {
211 const hash = parse_split(HashFn, "-").do(input) catch return false;211 const hash = parse_split(HashFn, "-").do(input) catch return false;
212 const file = try std.fs.cwd().openFile(file_path, .{});212 const file = try std.fs.cwd().openFile(file_path, .{});
213 defer file.close();213 defer file.close();
214 const data = try file.reader().readAllAlloc(gpa, gb);214 const data = try file.reader().readAllAlloc(alloc, gb);
215 const expected = hash.string;215 const expected = hash.string;
216 const actual = switch (hash.id) {216 const actual = switch (hash.id) {
217 .blake3 => try do_hash(std.crypto.hash.Blake3, data),217 .blake3 => try do_hash(std.crypto.hash.Blake3, data),