CPAN-Checksums
view release on metacpan or search on metacpan
lib/CPAN/Checksums.pm view on Meta::CPAN
if (-d File::Spec->catdir($dirname,$de)){
$dref->{$de}{isdir} = 1;
} else {
my @stat = stat $abs or next DIRENT;
$dref->{$de}{size} = $stat[7];
my(@gmtime) = gmtime $stat[9];
$gmtime[4]++;
$gmtime[5]+=1900;
$dref->{$de}{mtime} = sprintf "%04d-%02d-%02d", @gmtime[5,4,3];
_add_digests($de,$dref,"Digest::SHA",[256],"sha256",$abs,$old_dref);
my $can_reuse_old_md5 = 1;
COMPARE: for my $param (qw(size mtime sha256)) {
if (!exists $old_dref->{$de}{$param} ||
$dref->{$de}{$param} ne $old_dref->{$de}{$param}) {
$can_reuse_old_md5 = 0;
last COMPARE;
}
}
if ($can_reuse_old_md5
and $de =~ /\.(gz|tgz|bz2|tbz)$/
and exists $old_dref->{$de}{md5}
and !exists $old_dref->{$de}{"md5-ungz"}
and !exists $old_dref->{$de}{"md5-unbz2"}
) {
$can_reuse_old_md5 = 0;
}
if ( $can_reuse_old_md5 ) {
MD5KEY: for my $param (qw(md5 md5-ungz md5-unbz2)) {
next MD5KEY unless exists $old_dref->{$de}{$param};
$dref->{$de}{$param} = $old_dref->{$de}{$param};
}
} else {
_add_digests($de,$dref,"Digest::MD5",[],"md5",$abs,$old_dref);
}
} # ! -d
$dref->{$de}{cpan_path} = $cpan_path;
}
$dh->close;
$dref;
}
sub _read_old_ddump {
my($ckfn) = @_;
my $is_signed = 0;
my($fh) = new IO::File;
my $old_ddump = "";
if ($fh->open($ckfn)) {
local $/ = "\n";
while (<$fh>) {
next if /^\#/;
$is_signed = 1 if /SIGNED MESSAGE/;
$old_ddump .= $_;
}
close $fh;
}
return($old_ddump,$is_signed);
}
sub updatedir ($;$) {
my($dirname, $root) = @_;
my $ckfn = File::Spec->catfile($dirname, "CHECKSUMS"); # checksum-file-name
my($old_ddump,$is_signed) = _read_old_ddump($ckfn);
my($old_dref) = makehashref($old_ddump);
my $dref = _dir_to_dref($dirname,$old_dref,$root);
local $Data::Dumper::Indent = 1;
local $Data::Dumper::Quotekeys = 1;
local $Data::Dumper::Sortkeys = 1;
my $ddump = Data::Dumper->new([$dref],["cksum"])->Dump;
my @ckfnstat = stat $ckfn;
if ($old_ddump) {
local $DIRNAME = $dirname;
if ( !!$SIGNING_KEY == !!$is_signed ) { # either both or neither
if (!$MIN_MTIME_CHECKSUMS || $ckfnstat[9] > $MIN_MTIME_CHECKSUMS ) {
# recent enough
return 1 if $old_ddump eq $ddump;
return 1 if ckcmp($old_dref,$dref);
}
}
if ($CAUTION) {
my $report = investigate($old_dref,$dref);
warn $report if $report;
}
}
my $ft = File::Temp->new(
DIR => $dirname,
TEMPLATE => "CHECKSUMS.XXXX",
CLEANUP => 0,
) or die;
my $tckfn = $ft->filename;
close $ft;
my($fh) = new IO::File;
open $fh, ">$tckfn\0" or die "Couldn't open >$tckfn\: $!";
local $\;
if ($SIGNING_KEY) {
print $fh "0&&<<''; # this PGP-signed message is also valid perl\n";
close $fh;
open $fh, "| $SIGNING_PROGRAM $SIGNING_KEY >> $tckfn"
or die "Could not call gpg: $!";
$ddump .= "__END__\n";
}
my $message = sprintf "# CHECKSUMS file written on %s GMT by CPAN::Checksums (v%s)\n%s",
scalar gmtime, $VERSION, $ddump;
print $fh $message;
my $success = close $fh;
if ($SIGNING_KEY && !$success) {
warn "Couldn't run '$SIGNING_PROGRAM $SIGNING_KEY'!
Writing to $tckfn directly";
open $fh, ">$tckfn\0" or die "Couldn't open >$tckfn\: $!";
print $fh $message;
close $fh or warn "Couldn't close $tckfn: $!";
}
chmod 0644, $ckfn or die "Couldn't chmod to 0644 for $ckfn\: $!" if -f $ckfn;
rename $tckfn, $ckfn or die "Could not rename: $!";
chmod 0444, $ckfn or die "Couldn't chmod to 0444 for $ckfn\: $!";
return 2;
}
( run in 0.562 second using v1.01-cache-2.11-cpan-524268b4103 )