diff options
| author | Nicolas Vigier <boklm@torproject.org> | 2020-02-12 16:09:00 +0100 |
|---|---|---|
| committer | Nicolas Vigier <boklm@torproject.org> | 2020-02-12 18:36:24 +0100 |
| commit | e4f12abe9ed81050994b5345c21b988005259396 (patch) | |
| tree | 9b9e0d5b7ff5f9e818a267f280b2c891e228e029 | |
| parent | ce6b9136fc9e006536b34844946d67aa92cc0c21 (diff) | |
Bug 33283: Avoid computing sha256sum of files multiple timesbug_33283_v2
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.
| -rw-r--r-- | lib/RBM.pm | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -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'); |
