[tbb-commits] [rbm/master] Bug 33283: Avoid computing sha256sum of files multiple times
sysrqb at torproject.org
sysrqb at torproject.org
Wed Feb 19 17:49:43 UTC 2020
commit e4f12abe9ed81050994b5345c21b988005259396
Author: Nicolas Vigier <boklm at torproject.org>
Date: Wed Feb 12 16:09:00 2020 +0100
Bug 33283: Avoid computing sha256sum of files multiple times
Instead, use the sha256file functon, which keeps the sha256sum of
files to avoid computing it twice. The function can now take a HASH as a
second argument, which can contain the key remove_cache indicating that
the sha256sum of a file should be cleared: we use this when we
find that a file has the wrong checksum and needs to be downloaded
again.
---
lib/RBM.pm | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/RBM.pm b/lib/RBM.pm
index f419c24..375648f 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -610,6 +610,11 @@ sub maketar {
sub sha256file {
CORE::state %res;
my $f = rbm_path(shift);
+ my $opt = shift;
+ if (ref $opt eq 'HASH' && $opt->{remove_cache}) {
+ delete $res{$f};
+ return;
+ }
return $res{$f} if exists $res{$f};
return $res{$f} = -f $f ? sha256_hex(path($f)->slurp_raw) : '';
}
@@ -724,7 +729,8 @@ sub input_file_need_dl {
return undef if $action eq 'getfpaths';
if ($fname
&& $input_file->{sha256sum}
- && $t->('sha256sum') ne sha256_hex(path($fname)->slurp_raw)) {
+ && $t->('sha256sum') ne sha256file($fname)) {
+ sha256file($fname, { remove_cache => 1 });
$fname = undef;
}
if ($action eq 'input_files_id') {
@@ -928,7 +934,7 @@ sub input_files {
}
exit_error "Missing file $name" unless $fname;
if ($t->('sha256sum')
- && $t->('sha256sum') ne sha256_hex(path($fname)->slurp_raw)) {
+ && $t->('sha256sum') ne sha256file($fname)) {
exit_error "Can't have sha256sum on directory: $fname" if -d $fname;
exit_error "Wrong sha256sum for $fname.\n" .
"Expected sha256sum: " . $t->('sha256sum');
More information about the tbb-commits
mailing list