diff options
author | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2013-08-28 23:03:38 +0100 |
---|---|---|
committer | Ian Jackson <ijackson@chiark.greenend.org.uk> | 2013-08-28 23:03:38 +0100 |
commit | bd9da469ec0702223270445ced410a54fb3d5158 (patch) | |
tree | 89e785ee50ba8db67e5ec15e0b33c34e8b68945f | |
parent | 3c24da0438db18fb49b0458b97613bdb9e6797a1 (diff) |
Reuse already-downloaded .orig files after checking their hashes. Closes: #720526. (This introduces a dependency on the Digest::SHA.)
-rw-r--r-- | debian/changelog | 2 | ||||
-rw-r--r-- | debian/control | 2 | ||||
-rwxr-xr-x | dgit | 30 |
3 files changed, 22 insertions, 12 deletions
diff --git a/debian/changelog b/debian/changelog index 2f80f28..cb80d51 100644 --- a/debian/changelog +++ b/debian/changelog @@ -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. diff --git a/debian/control b/debian/control index 986189d..8f15413 100644 --- a/debian/control +++ b/debian/control @@ -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 @@ -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; } |