Subversion Repositories debpool

Compare Revisions

Ignore whitespace Rev 7 → Rev 8

/branches/magnus/debian/changelog
4,8 → 4,12
.dsc and .changes files have to be signed.
* Release.pm: Store the checksum hashes in a list instead of a hash
(Closes: #415323).
* Release.pm: Simplify Generate_Release_Triple() and
Generate_Release_Dist() by factoring out the checksum calculation to
Compute_Checksums(). Furthermore, instead of reading the whole file
into memory, create digester objects and let them read the file.
 
-- Magnus Holmgren <magnus@kibibyte.se> Sun, 1 Apr 2007 15:11:37 +0200
-- Magnus Holmgren <magnus@kibibyte.se> Sun, 1 Apr 2007 15:14:31 +0200
 
debpool (0.2.3) experimental; urgency=low
 
/branches/magnus/share/DebPool/Release.pm
105,6 → 105,52
 
### Meaningful functions
 
# Compute_Checksums($basepath, $filename)
#
# Compute MD5 and SHA1 checksums of a file. The checksums are stored,
# together with the filename and the file size, in a hash, a reference
# to which is returned.
#
# Returns undef on error.
 
sub Compute_Checksums {
my($basepath, $filename) = @_;
my($fh);
 
# Open the file and read in the contents. This could be a very
# large amount of data, but unfortunately, both Digets routines
# require the entire thing at once.
unless (open($fh, '<', "$basepath/$filename") && binmode($fh)) {
$Error = "Couldn't open file '$basepath/$filename' for reading.";
return undef;
}
# Grab the filesize from stat()
my(@stat) = stat($fh);
my $ret = {
'File' => $filename,
'Size' => $stat[7],
};
my %digesters = ('MD5Sum' => new Digest::MD5,
'SHA1' => new Digest::SHA1);
# Now calculate the checksums and put them into the hashes.
while (my ($algo, $dig) = each %digesters) {
eval {
seek $fh, 0, 0 or die $!;
$ret->{$algo} = $dig->addfile($fh)->hexdigest;
};
if ($@) {
$Error = "Failed to compute $algo for '$basepath/$filename': $@";
close $fh;
return undef;
}
}
return $ret;
}
 
# Generate_Release_Triple($archive, $component, $architecture, $version)
#
# Generate a Release file for a specific dist/component/arch, in the
144,35 → 190,8
if (0 == grep(/^$ck_file$/, @SigFiles)) { # We don't care about it.
next;
}
 
# Grab the filesize from stat()
 
my(@stat) = stat("${dirpath}/${ck_file}");
my($size) = $stat[7];
 
# Open the file and read in the contents. This could be a very
# large amount of data, but unfortunately, both Digest routines
# require the entire thing at once.
 
if (!open(CK_FILE, '<', "${dirpath}/${ck_file}")) {
$Error = "Couldn't open file '${dirpath}/${ck_file}' for reading.";
return undef;
}
 
my(@filetext) = <CK_FILE>;
close(CK_FILE);
 
# Now calculate the checksums and put them into the hashes.
 
my($md5) = Digest::MD5::md5_hex(@filetext);
my($sha1) = Digest::SHA1::sha1_hex(@filetext);
 
push @Checksums, {
'File' => $ck_file,
'Size' => $size,
'MD5' => $md5,
'SHA1' => $sha1,
};
my $checksum = Compute_Checksums($dirpath, $ck_file) or return undef;
push @Checksums, $checksum;
}
 
# Open a secure tempfile, and write the headers to it.
197,16 → 216,13
 
# Now print MD5 and SHA1 checksum lists.
 
print $tmpfile_handle "MD5Sum:\n";
foreach my $checksum (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $checksum->{'MD5'},
$checksum->{'Size'}, $checksum->{'File'};
}
foreach my $algo ('MD5Sum', 'SHA1') {
print $tmpfile_handle "$algo:\n";
 
print $tmpfile_handle "SHA1:\n";
foreach my $checksum (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $checksum->{'SHA1'},
foreach my $checksum (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $checksum->{$algo},
$checksum->{'Size'}, $checksum->{'File'};
}
}
 
close($tmpfile_handle);
240,32 → 256,10
 
my($file);
for $file (@files) {
my($fullfile) = "${dists_dir}/${archive}/${file}";
 
# Now, for each file, generate MD5 and SHA1 checksums, and put them
# into Checksums for later use (assuming it's a file we care about).
my(@stat) = stat($fullfile);
my($size) = $stat[7];
if (!open(HASH_FILE, '<', $fullfile)) {
$Error = "Couldn't open file '${fullfile} for reading.";
return undef;
}
my(@filetext) = <HASH_FILE>;
close(HASH_FILE);
 
# Now calculate the checksums and put them into the hashes.
my($md5) = Digest::MD5::md5_hex(@filetext);
my($sha1) = Digest::SHA1::sha1_hex(@filetext);
push @Checksums, {
'File' => $file,
'Size' => $size,
'MD5' => $md5,
'SHA1' => $sha1,
};
my $checksum = Compute_Checksums("${dists_dir}/${archive}", $file) or return undef;
push @Checksums, $checksum;
}
 
# Open a secure tempfile, and set up some variables.
289,18 → 283,14
 
# Now print MD5 and SHA1 checksum lists.
 
print $tmpfile_handle "MD5Sum:\n";
foreach $file (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $file->{'MD5'},
$file->{'Size'}, $file->{'File'};
}
foreach my $algo ('MD5Sum', 'SHA1') {
print $tmpfile_handle "$algo:\n";
 
print $tmpfile_handle "SHA1:\n";
foreach $file (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $file->{'SHA1'},
$file->{'Size'}, $file->{'File'};
foreach my $checksum (@Checksums) {
printf $tmpfile_handle " %s %8d %s\n", $checksum->{$algo},
$checksum->{'Size'}, $checksum->{'File'};
}
}
 
close($tmpfile_handle);
 
return $tmpfile_name;