Added pure perl fallback for Digest::SHA for old windows boxes

This commit is contained in:
Clinton Gormley 2015-08-05 13:58:09 +02:00
parent da31fbe702
commit 60f8fa4451
1 changed files with 13 additions and 2 deletions

View File

@ -8,11 +8,22 @@ use lib "$RealBin/lib";
use File::Spec();
use File::Temp();
use File::Find();
use Digest::SHA qw(sha1);
use File::Basename qw(basename);
use Archive::Extract();
$Archive::Extract::PREFER_BIN = 1;
our $SHA_CLASS = 'Digest::SHA';
if ( eval { require Digest::SHA } ) {
$SHA_CLASS = 'Digest::SHA';
}
else {
print STDERR "Digest::SHA not available. "
. "Falling back to Digest::SHA::PurePerl\n";
require Digest::SHA::PurePerl;
$SHA_CLASS = 'Digest::SHA::PurePerl';
}
my $mode = shift(@ARGV) || "";
die usage() unless $mode =~ /^--(check|update)$/;
@ -230,7 +241,7 @@ sub calculate_shas {
#===================================
my %shas;
while ( my $file = shift() ) {
my $digest = eval { Digest::SHA->new(1)->addfile($file) }
my $digest = eval { $SHA_CLASS->new(1)->addfile($file) }
or die "Error calculating SHA1 for <$file>: $!\n";
$shas{ basename($file) . ".sha1" } = $digest->hexdigest;
}