The following commit has been merged in the master branch:
commit 1ae77b82cff5462acffad67e2999973df880f0b7
Author: Raphael Hertzog <[email protected]>
Date: Sun Jun 21 02:35:04 2009 +0200
dpkg-scan(packages|sources): support all checksums algo
Use Dpkg::Checksums to generate all supported checksums when possible.
diff --git a/debian/changelog b/debian/changelog
index 618b98a..17ec7bb 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -38,6 +38,8 @@ dpkg (1.15.3) UNRELEASED; urgency=low
filenames. Closes: #532222
* Skip dpkg-genchanges' warning about lower version numbers for backports
(recognized by ~bpo or ~vola in their version number). Closes: #525115
+ * Support all checksum algorithms in dpkg-scanpackages/dpkg-scansources.
+ Closes: #533828
[ Joachim Breitner ]
* Warn about unused substvars in dpkg-gencontrol. Closes: #532760
diff --git a/scripts/dpkg-scanpackages.pl b/scripts/dpkg-scanpackages.pl
index 9c83356..e8ab441 100755
--- a/scripts/dpkg-scanpackages.pl
+++ b/scripts/dpkg-scanpackages.pl
@@ -10,6 +10,7 @@ use Dpkg::Gettext;
use Dpkg::ErrorHandling;
use Dpkg::Deps qw(@pkg_dep_fields);
use Dpkg::Version qw(compare_versions);
+use Dpkg::Checksums;
textdomain("dpkg-dev");
@@ -27,11 +28,17 @@ my %kmap= (optional => 'suggests',
package_revision => 'revision',
);
+my @sums;
+foreach (@check_supported) {
+ my $copy = uc($_);
+ $copy = "MD5sum" if $_ eq "md5";
+ push @sums, $copy;
+}
my @fieldpri = (qw(Package Package-Type Source Version Kernel-Version
Architecture Subarchitecture Essential Origin Bugs
Maintainer Installed-Size Installer-Menu-Item),
- @pkg_dep_fields, qw(Filename Size MD5sum Section Priority
- Homepage Description Tag));
+ @pkg_dep_fields, qw(Filename Size), @sums,
+ qw(Section Priority Homepage Description Tag));
# This maps the fields into the proper case
my %field_case;
@@ -217,17 +224,17 @@ FILE:
$tv{'Filename'}= "$pathprefix$fn";
- open(C,"md5sum <$fn |") || die "$fn $!";
- chop($_ = <C>);
- close(C);
- $? and subprocerr("'md5sum < %s'", $fn);;
- /^([0-9a-f]{32})\s*-?\s*$/ or
- error(_g("Strange text from 'md5sum < %s': '%s'"), $fn, $_);
- $tv{'MD5sum'}= $1;
-
- my @stat = stat($fn) or syserr(_g("Couldn't stat %s"), $fn);
- $stat[7] or error(_g("file %s is empty"), $fn);
- $tv{'Size'}= $stat[7];
+ my $sums = {};
+ my $size;
+ getchecksums($fn, $sums, \$size);
+ foreach my $alg (@check_supported) {
+ if ($alg eq "md5") {
+ $tv{'MD5sum'} = $sums->{'md5'};
+ } else {
+ $tv{uc($alg)} = $sums->{$alg};
+ }
+ }
+ $tv{'Size'} = $size;
if (defined $tv{Revision} and length($tv{Revision})) {
$tv{Version}.= '-'.$tv{Revision};
diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl
index 95fb043..51ef9ec 100755
--- a/scripts/dpkg-scansources.pl
+++ b/scripts/dpkg-scansources.pl
@@ -30,6 +30,7 @@ use warnings;
use Dpkg;
use Dpkg::Gettext;
use Dpkg::ErrorHandling;
+use Dpkg::Checksums;
textdomain("dpkg-dev");
@@ -242,19 +243,13 @@ sub de_pgp {
sub read_dsc {
my $file = shift;
- my ($size, $md5, $nread, $contents);
+ my ($size, $nread, $contents);
unless (open FILE, $file) {
warning(_g("can't read %s: %s"), $file, $!);
return;
}
- $size = -s FILE;
- unless (defined $size) {
- warning(_g("error doing fstat on %s: %s"), $file, $!);
- return;
- }
-
$contents = '';
do {
$nread = read FILE, $contents, 16*1024, length $contents;
@@ -264,27 +259,9 @@ sub read_dsc {
}
} while $nread > 0;
- # Rewind the .dsc file and feed it to md5sum as stdin.
- my $pid = open MD5, '-|';
- unless (defined $pid) {
- warning(_g("can't fork: %s", $!));
- return;
- }
- if (!$pid) {
- open STDIN, '<&FILE' or syserr(_g("can't dup %s"), $file);
- seek STDIN, 0, 0 or syserr(_g("can't rewind %s"), $file);
- exec 'md5sum' or syserr(_g("can't exec md5sum"));
- }
- chomp($md5 = join '', <MD5>);
- unless (close MD5) {
- warning(close_msg, 'md5sum');
- return;
- }
- $md5 =~ s/ *-$//; # Remove trailing spaces and -, to work with GNU md5sum
- unless (length($md5) == 32 && $md5 !~ /[^\da-f]/i) {
- warning(_g("invalid md5 output for %s (%s)"), $file, $md5);
- return;
- }
+ # Get checksums
+ my $sums = {};
+ getchecksums($file, $sums, \$size);
unless (close FILE) {
warning(_g("error closing %s: %s"), $file, $!);
@@ -294,7 +271,7 @@ sub read_dsc {
$contents = de_pgp $file, $contents;
return unless defined $contents;
- return $size, $md5, $contents;
+ return $size, $sums, $contents;
}
# Given PREFIX and DSC-FILE, process the file and returning the source
@@ -305,7 +282,7 @@ sub process_dsc {
my ($source, @binary, $priority, $section, $maintainer_override,
$dir, $dir_field, $dsc_field_start);
- my ($size, $md5, $contents) = read_dsc $file or return;
+ my ($size, $sums, $contents) = read_dsc $file or return;
# Allow blank lines at the end of a file, because the other programs
# do.
@@ -403,7 +380,15 @@ sub process_dsc {
$dir_field .= "Directory: $dir\n";
# The files field will get an entry for the .dsc file itself.
- $dsc_field_start = "Files:\n $md5 $size $file\n";
+ my %listing;
+ foreach my $alg (@check_supported) {
+ if ($alg eq "md5") {
+ $listing{$alg} = "Files:\n $sums->{$alg} $size $file\n";
+ } else {
+ $listing{$alg} = "Checksum-" . ucfirst($alg) .
+ ":\n $sums->{$alg} $size $file\n";
+ }
+ }
# Loop through @field, doing nececessary processing and building up
# @new_field.
@@ -430,9 +415,16 @@ sub process_dsc {
push @new_field, $dir_field;
$dir_field = undef;
$_ = " $_" if length;
- $_ = "$dsc_field_start$_";
+ $_ = "$listing{md5}$_";
}
+ if (/Checksums-(.*):/i) {
+ my $alg = lc($1);
+ s/Checksums-([^:]*):\s*//i;
+ $_ = " $_" if length;
+ $_ = "$listing{$alg}$_";
+ }
+
# Modify the maintainer if necessary.
if ($maintainer_override
&& defined $maintainer_override->[O_MAINT_TO]
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]