Source: dpkg
Version: 1.19.2
Severity: wishlist
Tags: patch

Hi,

When passing the --hash= option, dpkg-scanpackages will still
calculate all supported checksum variants via a call to
checksums_get_list() in Dpkg::Checksums::add_from_file.

On my system, this results in calculating sha1, sha256 and md5sum
values even if we then go and throw all but one away (eg. using
--hash=sha256). This leaves a potential 3X speed improvement and
avoids needless disk I/O, etc.

Patch attached.


Regards,

-- 
      ,''`.
     : :'  :     Chris Lamb
     `. `'`      la...@debian.org / chris-lamb.co.uk
       `-
diff --git a/scripts/dpkg-scanpackages.pl b/scripts/dpkg-scanpackages.pl
index 05710ae..e9ff681 100755
--- a/scripts/dpkg-scanpackages.pl
+++ b/scripts/dpkg-scanpackages.pl
@@ -196,10 +196,8 @@ sub process_deb {
     $fields->{'Filename'} = "$pathprefix$fn";
 
     my $sums = Dpkg::Checksums->new();
-    $sums->add_from_file($fn);
-    foreach my $alg (checksums_get_list()) {
-        next if %hash and not $hash{$alg};
-
+    $sums->add_from_file($fn, checksums => \@checksums);
+    foreach my $alg (@checksums) {
         if ($alg eq 'md5') {
             $fields->{'MD5sum'} = $sums->get_checksum($fn, $alg);
         } else {
@@ -223,9 +221,9 @@ if (not (@ARGV >= 1 and @ARGV <= 3)) {
 
 my $type = $options{type} // 'deb';
 my $arch = $options{arch};
-%hash = map { $_ => 1 } split /,/, $options{hash} // '';
+@checksums = defined($options{hash}) ? split /,/, $options{hash} : 
checksums_get_list();
 
-foreach my $alg (keys %hash) {
+foreach my $alg (@checksums) {
     if (not checksums_is_supported($alg)) {
         usageerr(g_('unsupported checksum \'%s\''), $alg);
     }

Reply via email to