From c5a846b191e4bfa59346381d80de97508080eac2 Mon Sep 17 00:00:00 2001 From: Catherine Date: Sat, 18 May 2024 04:50:10 +0000 Subject: [PATCH] Do not depend on Nix tools in `fetch_local_hash`. --- lib/bundix/source.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bundix/source.rb b/lib/bundix/source.rb index 33a942a..00a1904 100644 --- a/lib/bundix/source.rb +++ b/lib/bundix/source.rb @@ -1,3 +1,5 @@ +require 'digest/sha2' + class Bundix class Fetcher def sh(*args, &block) @@ -111,7 +113,11 @@ def fetch_local_hash(spec) spec.source.caches.each do |cache| path = File.join(cache, "#{spec.full_name}.gem") next unless File.file?(path) - hash = nix_prefetch_url(path)&.[](SHA256_32) + hash = Digest::SHA256.file(path).digest.bytes + .reverse + .reduce(0) {|n, b| (n << 8) + b } + .digits(32).map {|d| "0123456789abcdfghijklmnpqrsvwxyz"[d] }.join.ljust(52, '0') + .reverse return format_hash(hash) if hash end