Explorar o código

dpkg-scanpackages: Add a new --hash option to enable specific file checksums

This allows to restrict the file checksums generated to the specified
comma-separated list.

Requested-by: Thorsten Glaser <tg@debian.org>
Guillem Jover %!s(int64=11) %!d(string=hai) anos
pai
achega
175ba32030
Modificáronse 3 ficheiros con 20 adicións e 1 borrados
  1. 2 0
      debian/changelog
  2. 6 1
      man/dpkg-scanpackages.1
  3. 12 0
      scripts/dpkg-scanpackages.pl

+ 2 - 0
debian/changelog

@@ -94,6 +94,8 @@ dpkg (1.17.14) UNRELEASED; urgency=low
   * Do not pipe the files to sign from dpkg-buildpackage to GnuPG. When GnuPG
   * Do not pipe the files to sign from dpkg-buildpackage to GnuPG. When GnuPG
     uses the gpg-agent it is unable to detect the correct tty configuration
     uses the gpg-agent it is unable to detect the correct tty configuration
     if stdin is a pipe instead of the current terminal. Closes: #762391
     if stdin is a pipe instead of the current terminal. Closes: #762391
+  * Add a new --hash option to enable generating only specific file checksums
+    in dpkg-scanpackages. Requested by Thorsten Glaser <tg@debian.org>.
 
 
   [ Raphaël Hertzog ]
   [ Raphaël Hertzog ]
   * Explain better in deb-triggers(5) why interest/activate-noawait should be
   * Explain better in deb-triggers(5) why interest/activate-noawait should be

+ 6 - 1
man/dpkg-scanpackages.1

@@ -2,7 +2,7 @@
 .\"
 .\"
 .\" Copyright © 1996 Michael Shields <shields@crosslink.net>
 .\" Copyright © 1996 Michael Shields <shields@crosslink.net>
 .\" Copyright © 2006 Frank Lichtenheld <djpig@debian.org>
 .\" Copyright © 2006 Frank Lichtenheld <djpig@debian.org>
-.\" Copyright © 2007 Guillem Jover <guillem@debian.org>
+.\" Copyright © 2007, 2009, 2011-2014 Guillem Jover <guillem@debian.org>
 .\" Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
 .\" Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
 .\"
 .\"
 .\" This is free software; you can redistribute it and/or modify
 .\" This is free software; you can redistribute it and/or modify
@@ -89,6 +89,11 @@ for more information on its format.
 Use a pattern consisting of \fI*_all.deb\fP and \fI*_arch.deb\fP instead of
 Use a pattern consisting of \fI*_all.deb\fP and \fI*_arch.deb\fP instead of
 scanning for all debs.
 scanning for all debs.
 .TP
 .TP
+.BR \-h ", " \-\-hash " \fIhash-list\fP"
+Only generate file hashes for the comma-specified list specified.
+The default is to generate all currently supported hashes.
+Supported values: \fBmd5\fP, \fBsha1\fP, \fBsha256\fP.
+.TP
 .BR \-m ", " \-\-multiversion
 .BR \-m ", " \-\-multiversion
 Include all found packages in the output.
 Include all found packages in the output.
 .TP
 .TP

+ 12 - 0
scripts/dpkg-scanpackages.pl

@@ -48,6 +48,7 @@ my %options = (help            => sub { usage(); exit 0; },
 	       version         => \&version,
 	       version         => \&version,
 	       type            => undef,
 	       type            => undef,
 	       arch            => undef,
 	       arch            => undef,
+	       hash            => undef,
 	       multiversion    => 0,
 	       multiversion    => 0,
 	       'extra-override'=> undef,
 	       'extra-override'=> undef,
                medium          => undef,
                medium          => undef,
@@ -58,6 +59,7 @@ my @options_spec = (
     'version',
     'version',
     'type|t=s',
     'type|t=s',
     'arch|a=s',
     'arch|a=s',
+    'hash|h=s',
     'multiversion|m!',
     'multiversion|m!',
     'extra-override|e=s',
     'extra-override|e=s',
     'medium|M=s',
     'medium|M=s',
@@ -75,6 +77,7 @@ sub usage {
 Options:
 Options:
   -t, --type <type>        scan for <type> packages (default is 'deb').
   -t, --type <type>        scan for <type> packages (default is 'deb').
   -a, --arch <arch>        architecture to scan for.
   -a, --arch <arch>        architecture to scan for.
+  -h, --hash <hash-list>   only generate hashes for the specified list.
   -m, --multiversion       allow multiple versions of a single package.
   -m, --multiversion       allow multiple versions of a single package.
   -e, --extra-override <file>
   -e, --extra-override <file>
                            use extra override file.
                            use extra override file.
@@ -163,6 +166,13 @@ if (not (@ARGV >= 1 and @ARGV <= 3)) {
 
 
 my $type = $options{type} // 'deb';
 my $type = $options{type} // 'deb';
 my $arch = $options{arch};
 my $arch = $options{arch};
+my %hash = map { $_ => 1 } split /,/, $options{hash} // '';
+
+foreach my $alg (keys %hash) {
+    if (not checksums_is_supported($alg)) {
+        usageerr(_g('unsupported checksum \'%s\''), $alg);
+    }
+}
 
 
 my @find_args;
 my @find_args;
 if ($options{arch}) {
 if ($options{arch}) {
@@ -233,6 +243,8 @@ FILE:
         my $sums = Dpkg::Checksums->new();
         my $sums = Dpkg::Checksums->new();
 	$sums->add_from_file($fn);
 	$sums->add_from_file($fn);
         foreach my $alg (checksums_get_list()) {
         foreach my $alg (checksums_get_list()) {
+            next if %hash and not $hash{$alg};
+
             if ($alg eq 'md5') {
             if ($alg eq 'md5') {
 	        $fields->{'MD5sum'} = $sums->get_checksum($fn, $alg);
 	        $fields->{'MD5sum'} = $sums->get_checksum($fn, $alg);
             } else {
             } else {