Subversion Repositories debpool

Compare Revisions

Regard whitespace Rev 10 → Rev 9

/branches/magnus/share/DebPool/Packages.pm
763,30 → 763,27
 
sub Verify_MD5 {
use DebPool::Logging qw(:functions :facility :level);
use Digest::MD5;
 
my($file, $md5) = @_;
my($fh);
 
# Read in and mangle the md5 output.
 
unless (open($fh, '<', $file) && binmode($fh)) {
my($msg) = "Can't open '$file' for reading: $!";
if (! -r $file) { # The file doesn't exist! Will be hard to checksum it...
my($msg) = "MD5 checksum unavailable: file '$file' does not exist!";
Log_Message($msg, LOG_GENERAL, LOG_ERROR);
return 0;
}
 
my($digester) = new Digest::MD5;
my($check_md5);
eval { # addfile can croak
$check_md5 = $digester->addfile($fh)->hexdigest;
};
if ($@) {
Log_Message("Failed to compute MD5 checksum for '$file': $@",
LOG_GENERAL, LOG_ERROR);
my($cmd_result) = `/usr/bin/md5sum $file`;
if (!$cmd_result) { # Failed to run md5sum for some reason
my($msg) = "MD5 checksum unavailable: file '$file'";
Log_Message($msg, LOG_GENERAL, LOG_ERROR);
return 0;
}
 
$cmd_result =~ m/^([[:xdigit:]]+)\s+/;
my($check_md5) = $1;
 
if ($md5 ne $check_md5) {
my($msg) = "MD5 checksum failure: file '$file', ";
$msg .= "expected '$md5', got '$check_md5'";