match hashing algorithm of zig package downloader
This commit is contained in:
parent
8bfd116c3b
commit
b5d3fbeb7b
1 changed files with 10 additions and 7 deletions
17
build.zig
17
build.zig
|
@ -334,12 +334,14 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
return self;
|
||||
}
|
||||
|
||||
pub fn getOutputPath(self: *Self) !struct { path: []const u8, hash: u64 } {
|
||||
var hasher = std.hash.Wyhash.init(0);
|
||||
const Algo = std.crypto.hash.sha2.Sha256;
|
||||
pub fn getOutputPath(self: *Self) !struct { path: []const u8, hash: [Algo.digest_length]u8 } {
|
||||
var hasher = Algo.init(.{});
|
||||
hasher.update(download_link);
|
||||
const cache_hash = hasher.final();
|
||||
var cache_hash: [Algo.digest_length]u8 = undefined;
|
||||
hasher.final(&cache_hash);
|
||||
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{x}", .{cache_hash}), fileNameNoExtension() });
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{s}", .{std.fmt.bytesToHex(cache_hash, .lower)}), fileNameNoExtension() });
|
||||
|
||||
return .{
|
||||
.path = cache_dir,
|
||||
|
@ -354,11 +356,12 @@ fn DownloadStep(comptime link: []const u8) type {
|
|||
const model_dir = fileNameNoExtension();
|
||||
|
||||
// Create a cache hash based on the URL
|
||||
var hasher = std.hash.Wyhash.init(0);
|
||||
var hasher = Algo.init(.{});
|
||||
hasher.update(link);
|
||||
const cache_hash = hasher.final();
|
||||
var cache_hash: [Algo.digest_length]u8 = undefined;
|
||||
hasher.final(&cache_hash);
|
||||
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{x}", .{cache_hash}) });
|
||||
const cache_dir = try std.fs.path.join(self.builder.allocator, &[_][]const u8{ self.builder.cache_root.path.?, "o", try std.fmt.allocPrint(self.builder.allocator, "{s}", .{std.fmt.bytesToHex(cache_hash, .lower)}) });
|
||||
|
||||
const cached_model_dir = try std.fs.path.join(
|
||||
self.builder.allocator,
|
||||
|
|
Loading…
Add table
Reference in a new issue