chiark / gitweb /
Reuse already-downloaded .orig files after checking their hashes. Closes: #720526...
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 28 Aug 2013 22:03:38 +0000 (23:03 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 28 Aug 2013 22:03:38 +0000 (23:03 +0100)
debian/changelog
debian/control
dgit

index 2f80f284af8582895c1a88bd6667938c3464dcf3..cb80d511e8f7db5f68d785f11d22df12ad7c1bb6 100644 (file)
@@ -1,5 +1,7 @@
 dgit (0.13) unstable; urgency=low
 
+  * Reuse already-downloaded .orig files after checking their hashes.
+    Closes: #720526.  (This introduces a dependency on the Digest::SHA.)
   * Remove DGET_UNPACK from the environment in case the user has set it.
   * Remove scary warning from Description.
 
index 986189d18e5426a34099d8c49e9c39f2ade8767f..8f15413b959dd83af03b87f3d25adf108e5a9632 100644 (file)
@@ -7,7 +7,7 @@ Build-Depends: debhelper (>= 9)
 
 Package: dgit
 Depends: perl, libwww-perl, libdpkg-perl, git-core, devscripts, dpkg-dev,
-         ${misc:Depends}, realpath
+         ${misc:Depends}, realpath, libdigest-sha-perl
 Recommends: ssh-client
 Suggests: sbuild
 Architecture: all
diff --git a/dgit b/dgit
index a21cddec32952c26243ae029a9edd490cb39d3a3..4550a86d897a8bb2e208e62b7630f2838f8a7401 100755 (executable)
--- a/dgit
+++ b/dgit
@@ -513,21 +513,19 @@ sub mktree_in_ud_from_only_subdir () {
 }
 
 sub dsc_files_info () {
-    foreach my $csum (qw(Sha256 Sha1 MD5)) {
-       my $fname = $csum eq 'MD5' ? 'Files' : "Checksums-$csum";
+    foreach my $csumi (['Checksums-Sha256','Digest::SHA', 'new(256)'],
+                      ['Checksums-Sha1',  'Digest::SHA', 'new(1)'],
+                      ['Files',           'Digest::MD5', 'new()']) {
+       my ($fname, $module, $method) = @$csumi;
        my $field = $dsc->{$fname};
        next unless defined $field;
-       my $digest = uc $csum;
-       if (!eval "use Digest::$digest; 1;") {
-           print DEBUG "ignoring $fname because $@\n";
-           next;
-       }
+       eval "use $module; 1;" or die $@;
        my @out;
        foreach (split /\n/, $field) {
            next unless m/\S/;
            m/^(\w+) (\d+) (\S+)$/ or
                fail "could not parse .dsc $fname line \`$_'";
-           my $digester = eval "Digest::$digest->new;" or die $@;
+           my $digester = eval "$module"."->$method;" or die $@;
            push @out, {
                Hash => $1,
                Bytes => $2,
@@ -639,10 +637,20 @@ END
 }
 
 sub ensure_we_have_orig () {
-    foreach my $f (dsc_files()) {
+    foreach my $fi (dsc_files_info()) {
+       my $f = $fi->{Filename};
        next unless is_orig_file($f);
-       if (stat "../$f") {
-           die "$f ?" unless -f _;
+       if (open F, "<", "../$f") {
+           $fi->{Digester}->reset();
+           $fi->{Digester}->addfile(*F);
+           F->error and die $!;
+           my $got = $fi->{Digester}->hexdigest();
+           $got eq $fi->{Hash} or
+               fail "existing file $f has hash $got but .dsc".
+                   " demands hash $fi->{Hash}".
+                   " (perhaps you should delete this file?)";
+           print "using existing $f\n";
+           next;
        } else {
            die "$f $!" unless $!==&ENOENT;
        }