From: Ian Jackson Date: Tue, 10 Jan 2017 14:26:38 +0000 (+0000) Subject: dgit: complete_file_from_dsc: Introduce $checkhash X-Git-Tag: archive/debian/3.1~6 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=dgit.git;a=commitdiff_plain;h=2ad8f4f37376e982077ccdaaa13cdcc6b8da0705 dgit: complete_file_from_dsc: Introduce $checkhash No functional change. Signed-off-by: Ian Jackson --- diff --git a/dgit b/dgit index 135abe5f..39d439db 100755 --- a/dgit +++ b/dgit @@ -2465,6 +2465,19 @@ sub complete_file_from_dsc ($$) { my $tf = "$dstdir/$f"; my $downloaded = 0; + my $checkhash = sub { + open F, "<", "$tf" or die "$tf: $!"; + $fi->{Digester}->reset(); + $fi->{Digester}->addfile(*F); + F->error and die $!; + my $got = $fi->{Digester}->hexdigest(); + $got eq $fi->{Hash} or + fail "file $f has hash $got but .dsc". + " demands hash $fi->{Hash} ". + ($downloaded ? "(got wrong file from archive!)" + : "(perhaps you should delete this file?)"); + }; + if (stat_exists $tf) { progress "using existing $f"; } else { @@ -2479,16 +2492,7 @@ sub complete_file_from_dsc ($$) { $downloaded = 1; } - open F, "<", "$tf" or die "$tf: $!"; - $fi->{Digester}->reset(); - $fi->{Digester}->addfile(*F); - F->error and die $!; - my $got = $fi->{Digester}->hexdigest(); - $got eq $fi->{Hash} or - fail "file $f has hash $got but .dsc". - " demands hash $fi->{Hash} ". - ($downloaded ? "(got wrong file from archive!)" - : "(perhaps you should delete this file?)"); + $checkhash->(); return 1; }