commit 236fcaac2012531330f21d2e9cce49a534a03b60
Author: Nicolas Vigier <boklm(a)torproject.org>
Date: Mon Sep 18 17:38:13 2017 +0200
Bug 23557: download again an input file not matching expected sha256sum
When an input file is already present (downloaded during a previous
build), but is not matching the expected sha256sum, we download it
again.
To do that we rename the input_file_id_need_dl function to
input_file_need_dl, and make it work for all types of actions (instead
of only 'input_files_id' before). In input_file_need_dl we ignore an
the file if it is not matching the expected sha256sum.
---
doc/rbm_input_files.asc | 7 +++++--
lib/RBM.pm | 35 ++++++++++++++++++++---------------
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/doc/rbm_input_files.asc b/doc/rbm_input_files.asc
index e24d349..2716b23 100644
--- a/doc/rbm_input_files.asc
+++ b/doc/rbm_input_files.asc
@@ -85,8 +85,11 @@ enable::
refresh_input::
By default, if the file is already present, it is not downloaded
- or created again. If this option is set to a true value, the
- file will be removed and created again on each run.
+ or created again, except when an sha256sum is defined and the
+ file present is not matching. If this option is set to a true
+ value, the file will be removed and created again on each run,
+ except when an sha256sum is defined and the file present is
+ matching.
sha256sum::
The sha256 checksum of the file. The build will fail with an
diff --git a/lib/RBM.pm b/lib/RBM.pm
index 96a1b9b..7850817 100644
--- a/lib/RBM.pm
+++ b/lib/RBM.pm
@@ -699,17 +699,25 @@ sub file_in_dir {
return map { -e "$_/$filename" ? "$_/$filename" : () } @dir;
}
-sub input_file_id_need_dl {
- my ($input_file, $t, $fname) = @_;
- return undef if $input_file->{input_file_id};
- return undef if $input_file->{sha256sum};
- return undef if $input_file->{exec};
- return undef if $fname;
- return 1 if $input_file->{URL};
- return 1 if $input_file->{content};
- return undef if $input_file->{project};
- return undef;
- exit_error "Missing file" unless $fname;
+sub input_file_need_dl {
+ my ($input_file, $t, $fname, $action) = @_;
+ return undef if $action eq 'getfpaths';
+ if ($fname
+ && $input_file->{sha256sum}
+ && $t->('sha256sum') ne sha256_hex(read_file($fname))) {
+ $fname = undef;
+ }
+ if ($action eq 'input_files_id') {
+ return undef if $input_file->{input_file_id};
+ return undef if $input_file->{sha256sum};
+ return undef if $input_file->{exec};
+ return undef if $fname;
+ return 1 if $input_file->{URL};
+ return 1 if $input_file->{content};
+ return undef;
+ }
+ return $t->('refresh_input') if $fname;
+ return 1;
}
sub input_file_id_hash {
@@ -751,7 +759,6 @@ sub input_files {
my %res_getfnames;
my @res_getfpaths;
my $getfnames_noname = 0;
- my $need_dl = $action ne 'getfpaths';
my $input_files_id = '';
$options = {$options ? %$options : ()};
my $input_files = project_config($project, 'input_files', $options);
@@ -829,10 +836,8 @@ sub input_files {
if $input_file->{project};
exit_error("Missing filename:\n" . pp($input_file)) unless $name;
my ($fname) = file_in_dir($name, $src_dir, $proj_out_dir);
- $need_dl = input_file_id_need_dl($input_file, $t, $fname)
- if $action eq 'input_files_id';
my $file_gpg_id = gpg_id($t->('file_gpg_id'));
- if ($need_dl && (!$fname || $t->('refresh_input'))) {
+ if (input_file_need_dl($input_file, $t, $fname, $action)) {
if ($t->('content')) {
write_file("$proj_out_dir/$name", $t->('content'));
} elsif ($t->('URL')) {