blib/lib/CPAN/Checksums.pm

filter: Statementstmt 78.7% 174 / 221 Branchbran 53.5% 60 / 112 Conditioncond 54.1% 33 / 61 MC/DCmcdc 15.6% 5 / 32 Subroutinesub 100% 19 / 19 Podpod 25.0% 1 / 4 totaltotal 65.0% 292 / 449 SCAR 57.1
CC
81
Cov
68%
_dir_to_dref
148.5
updatedir
35.7
_add_digests
34.8
CRAP 300.7
↑ Summary
1 # -*- cperl-indent-level: 2 -*-
2 package CPAN::Checksums;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 use vars qw(
6 $CAUTION
7 $DIRNAME
8 $IGNORE_MATCH
9 $MIN_MTIME_CHECKSUMS
10 $SIGNING_KEY
11 $SIGNING_PROGRAM
12 $TRY_SHORTNAME
13 $VERSION
14 @EXPORT_OK
15 @ISA
16 2 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 2 require Exporter;
19  
20 2 @ISA = qw(Exporter);
21 2 @EXPORT_OK = qw(updatedir);
22 2 $VERSION = "2.13";
23 2 $VERSION =~ s/_//;
24 2 ▶$CAUTION ||= 0;
Condition50%1/2
$CPAN::Checksums::CAUTION ||= 0
l!l
02
MC/DC0%0/1
$CPAN::Checksums::CAUTION ||= 0
$CPAN::Checksums::CAUTION
Truth table50%1/2
A
A= $CPAN::Checksums::CAUTION
Aresult
11
00
25 2 ▶$TRY_SHORTNAME ||= 0;
Condition50%1/2
$CPAN::Checksums::TRY_SHORTNAME ||= 0
l!l
02
MC/DC0%0/1
$CPAN::Checksums::TRY_SHORTNAME ||= 0
$CPAN::Checksums::TRY_SHORTNAME
Truth table50%1/2
A
A= $CPAN::Checksums::TRY_SHORTNAME
Aresult
11
00
26 2 ▶$SIGNING_PROGRAM ||= 'gpg --clearsign --default-key ';
Condition50%1/2
$CPAN::Checksums::SIGNING_PROGRAM ||= "gpg --clearsign --default-key "
l!l
02
MC/DC0%0/1
$CPAN::Checksums::SIGNING_PROGRAM ||= "gpg --clearsign --default-key "
$CPAN::Checksums::SIGNING_PROGRAM
Truth table50%1/2
A
A= $CPAN::Checksums::SIGNING_PROGRAM
Aresult
11
00
27 2 ▶$SIGNING_KEY ||= '';
Condition50%1/2
$CPAN::Checksums::SIGNING_KEY ||= ""
l!l
02
MC/DC0%0/1
$CPAN::Checksums::SIGNING_KEY ||= ""
$CPAN::Checksums::SIGNING_KEY
Truth table50%1/2
A
A= $CPAN::Checksums::SIGNING_KEY
Aresult
11
00
28 2 ▶$MIN_MTIME_CHECKSUMS ||= 0;
Condition50%1/2
$CPAN::Checksums::MIN_MTIME_CHECKSUMS ||= 0
l!l
02
MC/DC0%0/1
$CPAN::Checksums::MIN_MTIME_CHECKSUMS ||= 0
$CPAN::Checksums::MIN_MTIME_CHECKSUMS
Truth table50%1/2
A
A= $CPAN::Checksums::MIN_MTIME_CHECKSUMS
Aresult
11
00
29 2 $IGNORE_MATCH = qr{(?i-xsm:readme$)};
30  
31 2 ▶use DirHandle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use IO::File ();
Subroutine BEGIN: called CC=1 SCAR=0.0
33 2 ▶use Digest::MD5 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
34 2 ▶use Compress::Bzip2();
Subroutine BEGIN: called CC=1 SCAR=0.0
35 2 ▶use Compress::Zlib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
36 2 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
37 2 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 2 ▶use Data::Dumper ();
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use Data::Compare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 sub _dir_to_dref {
43 10 ▶ my($dirname,$old_dref,$root) = @_;
Subroutine _dir_to_dref: called CC=32 SCAR=50.0
44 10 my $cpan_path = File::Spec->abs2rel( $dirname, $root ) ;
45 10 my($dref) = {};
46 10 my($dh)= DirHandle->new;
47 10 my($fh) = new IO::File;
48 10 ▶ $dh->open($dirname) or die "Couldn't opendir $dirname\: $!";
Branch: 1 branch
BranchTrueFalseTotal
$dh->open($dirname) or die "Couldn't opendir ${dirname}: $!" 0 10 10
49 10 my(%shortnameseen);
50 10 DIRENT: for my $de ($dh->read) {
51 70 ▶ next DIRENT if $de =~ /^\./;
Branch: 1 branch
BranchTrueFalseTotal
if $de =~ /^\./ 20 50 70
52 50 ▶ next DIRENT if substr($de,0,9) eq "CHECKSUMS";
Branch: 1 branch
BranchTrueFalseTotal
if substr($de, 0, 9) eq "CHECKSUMS" 9 41 50
53 41 ▶ next DIRENT if $IGNORE_MATCH && $de =~ $IGNORE_MATCH;
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Checksums::IGNORE_MATCH and $de =~ /$CPAN::Checksums::IGNORE_MATCH/ 0 41 41
Condition33%1/3
$CPAN::Checksums::IGNORE_MATCH and $de =~ /$CPAN::Checksums::IGNORE_MATCH/
!ll&&!rl&&r
0410
MC/DC0%0/2
$CPAN::Checksums::IGNORE_MATCH and $de =~ /$CPAN::Checksums::IGNORE_MATCH/
$CPAN::Checksums::IGNORE_MATCH $de =~ /$CPAN::Checksums::IGNORE_MATCH/
Truth table33%1/3
A and B
A= $CPAN::Checksums::IGNORE_MATCHB= $de =~ /$CPAN::Checksums::IGNORE_MATCH/
ABresult
0X0
100
111
54  
55 41 my $abs = File::Spec->catfile($dirname,$de);
56  
57 #
58 # SHORTNAME offers an 8.3 name, probably not needed but it was
59 # always there,,,
60 #
61 41 ▶ if ($TRY_SHORTNAME) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Checksums::TRY_SHORTNAME) 0 41 41
62 0 my $shortname = lc $de;
63 0 $shortname =~ s/\.tar[._-]gz$/\.tgz/;
64 0 my $suffix;
65 0 ($suffix = $shortname) =~ s/.*\.//;
66 0 ▶ substr($suffix,3) = "" if length($suffix) > 3;
Branch: 1 branch
BranchTrueFalseTotal
if length $suffix > 3 0 0 0
67 0 my @p;
68 0 ▶ if ($shortname =~ /\-/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shortname =~ /\-/) { } 0 0 0
69 0 @p = $shortname =~ /(.{1,16})-.*?([\d\.]{2,8})/;
70 } else {
71 0 @p = $shortname =~ /(.{1,8}).*?([\d\.]{2,8})/;
72 }
73 0 ▶ $p[0] ||= lc $de;
Condition0%0/3
$p[0] ||= lc $de
l!l&&r!l&&!r
000
MC/DC0%0/2
$p[0] ||= lc $de
$p[0] lc $de
Truth table0%0/3
A ||= B
A= $p[0]B= lc $de
ABresult
1X1
011
000
74 0 $p[0] =~ s/[^a-z0-9]//g;
75 0 ▶ $p[1] ||= 0;
Condition0%0/2
$p[1] ||= 0
l!l
00
MC/DC0%0/1
$p[1] ||= 0
$p[1]
Truth table0%0/2
A
A= $p[1]
Aresult
11
00
76 0 $p[1] =~ s/\D//g;
77 0 my $counter = 7;
78 0 ▶ while (length($p[0]) + length($p[1]) > 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($p[0]) + length($p[1]) > 8) 0 0 0
79 0 ▶ substr($p[0], $counter) = "" if length($p[0]) > $counter;
Branch: 1 branch
BranchTrueFalseTotal
if length $p[0] > $counter 0 0 0
80 0 ▶ substr($p[1], $counter) = "" if length($p[1]) > $counter--;
Branch: 1 branch
BranchTrueFalseTotal
if length $p[1] > $counter-- 0 0 0
81 }
82 0 ▶ my $dot = $suffix ? "." : "";
Branch: 1 branch
BranchTrueFalseTotal
$suffix ? : 0 0 0
83 0 $shortname = "$p[0]$p[1]$dot$suffix";
84 0 ▶ while (exists $shortnameseen{$shortname}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $shortnameseen{$shortname}) 0 0 0
85 0 my($modi) = $shortname =~ /([a-z\d]+)/;
86 0 $modi++;
87 0 $shortname = "$modi$dot$suffix";
88 0 ▶ if (++$counter > 1000){ # avoid endless loops and accept the buggy choice
Branch: 1 branch
BranchTrueFalseTotal
if (++$counter > 1000) 0 0 0
89 0 warn "Warning: long loop on shortname[$shortname]de[$de]";
90 0 last;
91 }
92 }
93 0 $dref->{$de}->{shortname} = $shortname;
94 0 $shortnameseen{$shortname} = undef; # for exists check good enough
95 }
96  
97 #
98 # STAT facts
99 #
100 41 ▶ if (-l File::Spec->catdir($dirname,$de)){
Branch: 1 branch
BranchTrueFalseTotal
if (-l "File::Spec"->catdir($dirname, $de)) 0 41 41
101 # Symlinks are a mess on a replicated, database driven system,
102 # but as they are not forbidden, we cannot ignore them. We do
103 # have a directory with nothing but a symlink in it. When we
104 # ignored the symlink, we did not write a CHECKSUMS file and
105 # CPAN.pm issued lots of warnings:-(
106 0 $dref->{$de}{issymlink} = 1;
107 }
108 41 ▶ if (-d File::Spec->catdir($dirname,$de)){
Branch: 1 branch
BranchTrueFalseTotal
if (-d 'File::Spec'->catdir($dirname, $de)) { } 0 41 41
109 0 $dref->{$de}{isdir} = 1;
110 } else {
111 41 ▶ my @stat = stat $abs or next DIRENT;
Branch: 1 branch
BranchTrueFalseTotal
my(@stat) = stat $abs or next DIRENT 0 41 41
112 41 $dref->{$de}{size} = $stat[7];
113 41 my(@gmtime) = gmtime $stat[9];
114 41 $gmtime[4]++;
115 41 $gmtime[5]+=1900;
116 41 $dref->{$de}{mtime} = sprintf "%04d-%02d-%02d", @gmtime[5,4,3];
117 41 _add_digests($de,$dref,"Digest::SHA",[256],"sha256",$abs,$old_dref);
118 41 my $can_reuse_old_md5 = 1;
119 41 COMPARE: for my $param (qw(size mtime sha256)) {
120 113 ▶ if (!exists $old_dref->{$de}{$param} ||
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $old_dref->{$de}{$param} or $dref->{$de}{$param} ne $old_dref->{$de}{$param}) 5 108 113
Condition100%3/3
not exists $old_dref->{$de}{$param} or $dref->{$de}{$param} ne $old_dref->{$de}{$param}
l!l&&r!l&&!r
23108
MC/DC100%2/2
not exists $old_dref->{$de}{$param} or $dref->{$de}{$param} ne $old_dref->{$de}{$param}
not exists $old_dref->{$de}{$param} $dref->{$de}{$param} ne $old_dref->{$de}{$param}
Truth table100%3/3
not(A) or B
A= not exists $old_dref->{$de}{$param}B= $dref->{$de}{$param} ne $old_dref->{$de}{$param}
ABresult
1X1
011
000
121 $dref->{$de}{$param} ne $old_dref->{$de}{$param}) {
122 5 $can_reuse_old_md5 = 0;
123 5 last COMPARE;
124 }
125 }
126 41 ▶ if ($can_reuse_old_md5
Branch: 1 branch
BranchTrueFalseTotal
if ($can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/ and exists $old_dref->{$de}{"md5"} and not exists $old_dref->{$de}{"md5-ungz"} and not exists $old_dref->{$de}{"md5-unbz2"}) 0 41 41
Condition83%10/12
$can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/ and exists $old_dref->{$de}{"md5"} and not exists $old_dref->{$de}{"md5-ungz"} and not exists $old_dref->{$de}{"md5-unbz2"}
!ll&&!rl&&r
3650
$can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/ and exists $old_dref->{$de}{"md5"} and not exists $old_dref->{$de}{"md5-ungz"}
!ll&&!rl&&r
3155
$can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/ and exists $old_dref->{$de}{"md5"}
!ll&&!rl&&r
31010
$can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/
!ll&&!rl&&r
52610
MC/DC0%0/5
$can_reuse_old_md5 and $de =~ /\.(gz|tgz|bz2|tbz)$/ and exists $old_dref->{$de}{"md5"} and not exists $old_dref->{$de}{"md5-ungz"} and not exists $old_dref->{$de}{"md5-unbz2"}
$can_reuse_old_md5 $de =~ /\.(gz|tgz|bz2|tbz)$/ exists $old_dref->{$de}{"md5"} not exists $old_dref->{$de}{"md5-ungz"} not exists $old_dref->{$de}{"md5-unbz2"}
Truth table66%4/6
A and B and C and not(D) and not(E)
A= $can_reuse_old_md5B= $de =~ /\.(gz|tgz|bz2|tbz)$/C= exists $old_dref->{$de}{"md5"}D= not exists $old_dref->{$de}{"md5-ungz"}E= not exists $old_dref->{$de}{"md5-unbz2"}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
127 and $de =~ /\.(gz|tgz|bz2|tbz)$/
128 and exists $old_dref->{$de}{md5}
129 and !exists $old_dref->{$de}{"md5-ungz"}
130 and !exists $old_dref->{$de}{"md5-unbz2"}
131 ) {
132 0 $can_reuse_old_md5 = 0;
133 }
134 41 ▶ if ( $can_reuse_old_md5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($can_reuse_old_md5) { } 36 5 41
135 36 MD5KEY: for my $param (qw(md5 md5-ungz md5-unbz2)) {
136 108 ▶ next MD5KEY unless exists $old_dref->{$de}{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $old_dref->{$de}{$param} 62 46 108
137 46 $dref->{$de}{$param} = $old_dref->{$de}{$param};
138 }
139 } else {
140 5 _add_digests($de,$dref,"Digest::MD5",[],"md5",$abs,$old_dref);
141 }
142  
143 } # ! -d
144 41 $dref->{$de}{cpan_path} = $cpan_path;
145  
146 }
147 10 $dh->close;
148 10 $dref;
149 }
150  
151 sub _read_old_ddump {
152 10 ▶ my($ckfn) = @_;
Subroutine _read_old_ddump: called CC=5 SCAR=16.1
153 10 my $is_signed = 0;
154 10 my($fh) = new IO::File;
155 10 my $old_ddump = "";
156 10 ▶ if ($fh->open($ckfn)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->open($ckfn)) 9 1 10
157 9 local $/ = "\n";
158 9 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 327 9 336
159 327 ▶ next if /^\#/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\#/ 9 318 327
160 318 ▶ $is_signed = 1 if /SIGNED MESSAGE/;
Branch: 1 branch
BranchTrueFalseTotal
if /SIGNED MESSAGE/ 0 318 318
161 318 $old_ddump .= $_;
162 }
163 9 close $fh;
164 }
165 10 return($old_ddump,$is_signed);
166 }
167  
168 sub updatedir ($;$) {
169 10 ▶ my($dirname, $root) = @_;
Subroutine updatedir: called CC=21 SCAR=35.8
Pod documented
170 10 my $ckfn = File::Spec->catfile($dirname, "CHECKSUMS"); # checksum-file-name
171 10 my($old_ddump,$is_signed) = _read_old_ddump($ckfn);
172 10 my($old_dref) = makehashref($old_ddump);
173 10 my $dref = _dir_to_dref($dirname,$old_dref,$root);
174 10 local $Data::Dumper::Indent = 1;
175 10 local $Data::Dumper::Quotekeys = 1;
176 10 local $Data::Dumper::Sortkeys = 1;
177 10 my $ddump = Data::Dumper->new([$dref],["cksum"])->Dump;
178 10 my @ckfnstat = stat $ckfn;
179 10 ▶ if ($old_ddump) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_ddump) 9 1 10
180 9 local $DIRNAME = $dirname;
181 9 ▶ if ( !!$SIGNING_KEY == !!$is_signed ) { # either both or neither
Branch: 1 branch
BranchTrueFalseTotal
if (!!$CPAN::Checksums::SIGNING_KEY == !!$is_signed) 9 0 9
182 9 ▶ if (!$MIN_MTIME_CHECKSUMS || $ckfnstat[9] > $MIN_MTIME_CHECKSUMS ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $CPAN::Checksums::MIN_MTIME_CHECKSUMS or $ckfnstat[9] > $CPAN::Checksums::MIN_MTIME_CHECKSUMS) 8 1 9
Condition66%2/3
not $CPAN::Checksums::MIN_MTIME_CHECKSUMS or $ckfnstat[9] > $CPAN::Checksums::MIN_MTIME_CHECKSUMS
l!l&&r!l&&!r
801
MC/DC50%1/2
not $CPAN::Checksums::MIN_MTIME_CHECKSUMS or $ckfnstat[9] > $CPAN::Checksums::MIN_MTIME_CHECKSUMS
not $CPAN::Checksums::MIN_MTIME_CHECKSUMS $ckfnstat[9] > $CPAN::Checksums::MIN_MTIME_CHECKSUMS
Truth table66%2/3
not(A) or B
A= not $CPAN::Checksums::MIN_MTIME_CHECKSUMSB= $ckfnstat[9] > $CPAN::Checksums::MIN_MTIME_CHECKSUMS
ABresult
1X1
011
000
183 # recent enough
184 8 ▶ return 1 if $old_ddump eq $ddump;
Branch: 1 branch
BranchTrueFalseTotal
if $old_ddump eq $ddump 4 4 8
185 4 ▶ return 1 if ckcmp($old_dref,$dref);
Branch: 1 branch
BranchTrueFalseTotal
if &ckcmp($old_dref, $dref) 0 4 4
186 }
187 }
188 5 ▶ if ($CAUTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Checksums::CAUTION) 1 4 5
189 1 my $report = investigate($old_dref,$dref);
190 1 ▶ warn $report if $report;
Branch: 1 branch
BranchTrueFalseTotal
if $report 1 0 1
191 }
192 }
193 6 ▶ my $ft = File::Temp->new(
Branch: 1 branch
BranchTrueFalseTotal
my $ft = "File::Temp"->new("DIR", $dirname, "TEMPLATE", "CHECKSUMS.XXXX", "CLEANUP", 0) or die 0 6 6
194 DIR => $dirname,
195 TEMPLATE => "CHECKSUMS.XXXX",
196 CLEANUP => 0,
197 ) or die;
198 6 my $tckfn = $ft->filename;
199 6 close $ft;
200 6 my($fh) = new IO::File;
201 6 ▶ open $fh, ">$tckfn\0" or die "Couldn't open >$tckfn\: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$tckfn\000" or die "Couldn't open >${tckfn}: $!" 0 6 6
202  
203 6 local $\;
204 6 ▶ if ($SIGNING_KEY) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Checksums::SIGNING_KEY) 0 6 6
205 0 print $fh "0&&<<''; # this PGP-signed message is also valid perl\n";
206 0 close $fh;
207 0 ▶ open $fh, "| $SIGNING_PROGRAM $SIGNING_KEY >> $tckfn"
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "| $CPAN::Checksums::SIGNING_PROGRAM $CPAN::Checksums::SIGNING_KEY >> $tckfn" or die "Could not call gpg: $!" 0 0 0
208 or die "Could not call gpg: $!";
209 0 $ddump .= "__END__\n";
210 }
211  
212 6 my $message = sprintf "# CHECKSUMS file written on %s GMT by CPAN::Checksums (v%s)\n%s",
213 scalar gmtime, $VERSION, $ddump;
214 6 print $fh $message;
215 6 my $success = close $fh;
216 6 ▶ if ($SIGNING_KEY && !$success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Checksums::SIGNING_KEY and not $success) 0 6 6
Condition33%1/3
$CPAN::Checksums::SIGNING_KEY and not $success
!ll&&!rl&&r
600
MC/DC0%0/2
$CPAN::Checksums::SIGNING_KEY and not $success
$CPAN::Checksums::SIGNING_KEY not $success
Truth table33%1/3
A and not(B)
A= $CPAN::Checksums::SIGNING_KEYB= not $success
ABresult
0X0
100
111
217 0 warn "Couldn't run '$SIGNING_PROGRAM $SIGNING_KEY'!
218 Writing to $tckfn directly";
219 0 ▶ open $fh, ">$tckfn\0" or die "Couldn't open >$tckfn\: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">$tckfn\000" or die "Couldn't open >${tckfn}: $!" 0 0 0
220 0 print $fh $message;
221 0 ▶ close $fh or warn "Couldn't close $tckfn: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "Couldn't close ${tckfn}: $!" 0 0 0
222 }
223 6 ▶ chmod 0644, $ckfn or die "Couldn't chmod to 0644 for $ckfn\: $!" if -f $ckfn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $ckfn 5 1 6
Condition60%3/5
-f $ckfn && (chmod(0644, $ckfn) || die("Couldn't chmod to 0644 for ${ckfn}: $!"))
!ll&&!rl&&r
150
chmod 0644, $ckfn or die "Couldn't chmod to 0644 for ${ckfn}: $!"
l!l
50
MC/DC0%0/2
-f $ckfn && (chmod(0644, $ckfn) || die("Couldn't chmod to 0644 for ${ckfn}: $!"))
-f $ckfn chmod 0644, $ckfn
Truth table33%1/3
A && B
A= -f $ckfnB= chmod 0644, $ckfn
ABresult
0X0
100
111
224 6 ▶ rename $tckfn, $ckfn or die "Could not rename: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename $tckfn, $ckfn or die "Could not rename: $!" 0 6 6
225 6 ▶ chmod 0444, $ckfn or die "Couldn't chmod to 0444 for $ckfn\: $!";
Branch: 1 branch
BranchTrueFalseTotal
chmod 0444, $ckfn or die "Couldn't chmod to 0444 for ${ckfn}: $!" 0 6 6
226 6 return 2;
227 }
228  
229 sub _add_digests ($$$$$$$) {
230 46 ▶ my($de,$dref,$module,$constructor_args,$keyname,$abs,$old_dref) = @_;
Subroutine _add_digests: called CC=14 SCAR=35.5
231 46 my($fh) = new IO::File;
232 46 my $dig = $module->new(@$constructor_args);
233 46 ▶ $fh->open("$abs\0") or die "Couldn't open $abs: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open("$abs\000") or die "Couldn't open ${abs}: $!" 0 46 46
234 46 binmode($fh); # make sure it's called as a function, solaris with
235 # perl 5.8.4 complained about missing method in
236 # IO::File
237 46 $dig->addfile($fh);
238 46 $fh->close;
239 46 my $digest = $dig->hexdigest;
240 46 $dref->{$de}{$keyname} = $digest;
241 46 $dig = $module->new(@$constructor_args);
242 46 ▶ if ($de =~ /\.(gz|tgz)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($de =~ /\.(gz|tgz)$/) { } 5 41 46
elsif ($de =~ /\.(bz2|tbz)$/) { } 5 36 41
243 5 my($buffer, $zip);
244 5 ▶ if (exists $old_dref->{$de}{$keyname} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-ungz"}) 5 0 5
Condition33%2/6
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-ungz"}
!ll&&!rl&&r
005
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname}
!ll&&!rl&&r
005
MC/DC0%0/3
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-ungz"}
exists $old_dref->{$de}{$keyname} $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} exists $old_dref->{$de}{"$keyname-ungz"}
Truth table25%1/4
A and B and C
A= exists $old_dref->{$de}{$keyname}B= $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname}C= exists $old_dref->{$de}{"$keyname-ungz"}
ABCresult
0XX0
10X0
1100
1111
245 $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} &&
246 exists $old_dref->{$de}{"$keyname-ungz"}
247 ) {
248 5 $dref->{$de}{"$keyname-ungz"} = $old_dref->{$de}{"$keyname-ungz"};
249 5 return;
250 }
251 0 ▶ if ($zip = Compress::Zlib::gzopen($abs, "rb")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip = &Compress::Zlib::gzopen($abs, "rb")) 0 0 0
252 0 ▶ $dig->add($buffer)
Branch: 1 branch
BranchTrueFalseTotal
$zip->gzread($buffer) > 0 and do { $dig->add($buffer) } 0 0 0
253 while $zip->gzread($buffer) > 0;
254 0 $dref->{$de}{"$keyname-ungz"} = $dig->hexdigest;
255 0 $zip->gzclose;
256 }
257 } elsif ($de =~ /\.(bz2|tbz)$/) {
258 5 my($buffer, $zip);
259 5 ▶ if (exists $old_dref->{$de}{$keyname} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-unbz2"}) 5 0 5
Condition33%2/6
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-unbz2"}
!ll&&!rl&&r
005
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname}
!ll&&!rl&&r
005
MC/DC0%0/3
exists $old_dref->{$de}{$keyname} and $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} and exists $old_dref->{$de}{"$keyname-unbz2"}
exists $old_dref->{$de}{$keyname} $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} exists $old_dref->{$de}{"$keyname-unbz2"}
Truth table25%1/4
A and B and C
A= exists $old_dref->{$de}{$keyname}B= $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname}C= exists $old_dref->{$de}{"$keyname-unbz2"}
ABCresult
0XX0
10X0
1100
1111
260 $dref->{$de}{$keyname} eq $old_dref->{$de}{$keyname} &&
261 exists $old_dref->{$de}{"$keyname-unbz2"}
262 ) {
263 5 $dref->{$de}{"$keyname-unbz2"} = $old_dref->{$de}{"$keyname-unbz2"};
264 5 return;
265 }
266 0 ▶ if ($zip = Compress::Bzip2::bzopen($abs, "rb")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip = &Compress::Bzip2::bzopen($abs, "rb")) 0 0 0
267 0 ▶ $dig->add($buffer)
Branch: 1 branch
BranchTrueFalseTotal
$zip->bzread($buffer) > 0 and do { $dig->add($buffer) } 0 0 0
268 while $zip->bzread($buffer) > 0;
269 0 $dref->{$de}{"$keyname-unbz2"} = $dig->hexdigest;
270 0 $zip->bzclose;
271 }
272 }
273 }
274  
275 sub ckcmp ($$) {
276 4 ▶ my($old,$new) = @_;
Subroutine ckcmp: called CC=2 SCAR=6.9
Pod undocumented
277 4 for ($old,$new) {
278 8 $_ = makehashref($_);
279 }
280 4 Data::Compare::Compare($old,$new);
281 }
282  
283 # see if a file changed but the name not
284 sub investigate ($$) {
285 1 ▶ my($old,$new) = @_;
Subroutine investigate: called CC=9 SCAR=22.0
Pod undocumented
286 1 for ($old,$new) {
287 2 $_ = makehashref($_);
288 }
289 1 my $complain = "";
290 1 for my $dist (sort keys %$new) {
291 7 ▶ if (exists $old->{$dist}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $old->{$dist}) 7 0 7
292 7 my $headersaid;
293 7 for my $diff (qw/md5 sha256 size md5-ungz sha256-ungz mtime/) {
294 next unless exists $old->{$dist}{$diff} &&
295 42 ▶ exists $new->{$dist}{$diff};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $old->{$dist}{$diff} and exists $new->{$dist}{$diff} 12 30 42
Condition66%2/3
exists $old->{$dist}{$diff} and exists $new->{$dist}{$diff}
!ll&&!rl&&r
12030
MC/DC50%1/2
exists $old->{$dist}{$diff} and exists $new->{$dist}{$diff}
exists $old->{$dist}{$diff} exists $new->{$dist}{$diff}
Truth table66%2/3
A and B
A= exists $old->{$dist}{$diff}B= exists $new->{$dist}{$diff}
ABresult
0X0
100
111
296 30 ▶ next if $old->{$dist}{$diff} eq $new->{$dist}{$diff};
Branch: 1 branch
BranchTrueFalseTotal
if $old->{$dist}{$diff} eq $new->{$dist}{$diff} 26 4 30
297 4 ▶ $complain .=
Branch: 1 branch
BranchTrueFalseTotal
unless $headersaid++ 1 3 4
298 scalar gmtime().
299 " GMT:\ndiffering old/new version of same file $dist:\n"
300 unless $headersaid++;
301 4 $complain .=
302 qq{\t$diff "$old->{$dist}{$diff}" -> "$new->{$dist}{$diff}"\n}; #};
303 }
304 }
305 }
306 1 $complain;
307 }
308  
309 sub makehashref ($) {
310 20 ▶ local($_) = shift;
Subroutine makehashref: called CC=4 SCAR=13.9
Pod undocumented
311 20 ▶ unless (ref $_ eq "HASH") {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $_ eq "HASH") 10 10 20
312 10 require Safe;
313 10 my($comp) = Safe->new("CPAN::Checksums::reval");
314 10 my $cksum; # used by Data::Dumper
315 10 ▶ $_ = $comp->reval($_) || {};
Condition100%2/2
$comp->reval($_) || {}
l!l
91
MC/DC100%1/1
$comp->reval($_) || {}
$comp->reval($_)
Truth table100%2/2
A
A= $comp->reval($_)
Aresult
11
00
316 10 ▶ die "CPAN::Checksums: Caught error[$@] while checking $DIRNAME" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 10 10
317 }
318 20 $_;
319 }
320  
321 2 1;
322  
323 __END__
↑ Summary