chiark / gitweb /
dgit: complete_file_from_dsc: Introduce $refetched
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2017 14:34:08 +0000 (14:34 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 10 Jan 2017 14:51:43 +0000 (14:51 +0000)
Make have a option which, if set, causes hash mismatches to result in
a refetch rather than a crash.

No functional change because no call sites pass it.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
dgit

diff --git a/dgit b/dgit
index c801fa93b1f6bd4c784b0ddd5ce27acd9f19d900..0cd122ef23aaabec7537c3c4389a51947c89dbab 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -2456,10 +2456,12 @@ END
     return @output;
 }
 
-sub complete_file_from_dsc ($$) {
-    our ($dstdir, $fi) = @_;
-    # Ensures that we have, in $dir, the file $fi, with the correct
+sub complete_file_from_dsc ($$;$) {
+    our ($dstdir, $fi, $refetched) = @_;
+    # Ensures that we have, in $dstdir, the file $fi, with the correct
     # contents.  (Downloading it from alongside $dscurl if necessary.)
+    # If $refetched is defined, can overwrite "$dstdir/$fi->{Filename}"
+    # and will set $$refetched=1 if it did so (or tried to).
 
     my $f = $fi->{Filename};
     my $tf = "$dstdir/$f";
@@ -2476,24 +2478,34 @@ sub complete_file_from_dsc ($$) {
     };
 
     if (stat_exists $tf) {
-       progress "using existing $f";
+       if ($checkhash->()) {
+           progress "using existing $f";
+           return 1;
+       }
+       if (!$refetched) {
+           fail "file $f has hash $got but .dsc".
+               " demands hash $fi->{Hash} ".
+               "(perhaps you should delete this file?)";
+       }
+       progress "need to fetch correct version of $f";
+       unlink $tf or die "$tf $!";
+       $$refetched = 1;
     } else {
        printdebug "$tf does not exist, need to fetch\n";
-       my $furl = $dscurl;
-       $furl =~ s{/[^/]+$}{};
-       $furl .= "/$f";
-       die "$f ?" unless $f =~ m/^\Q${package}\E_/;
-       die "$f ?" if $f =~ m#/#;
-       runcmd_ordryrun_local @curl,qw(-f -o),$tf,'--',"$furl";
-       return 0 if !act_local();
-       $downloaded = 1;
     }
 
+    my $furl = $dscurl;
+    $furl =~ s{/[^/]+$}{};
+    $furl .= "/$f";
+    die "$f ?" unless $f =~ m/^\Q${package}\E_/;
+    die "$f ?" if $f =~ m#/#;
+    runcmd_ordryrun_local @curl,qw(-f -o),$tf,'--',"$furl";
+    return 0 if !act_local();
+
     $checkhash->() 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?)");
+           "(got wrong file from archive!)";
 
     return 1;
 }