Distribconf/Utils.pm

filter: Statementstmt 90.0% 63 / 70 Branchbran 69.2% 18 / 26 Conditioncond 63.1% 12 / 19 MC/DCmcdc 27.2% 3 / 11 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 77.7% 105 / 135 SCAR 33.3
CC
24
Cov
81%
hdlist_vs_dir
23.3
checkmd5
7.2
BEGIN
1.0
CRAP 28.0
« Distribconf.pm ↑ Summary Distribconf/MediaCFG.pm »
1 package MDV::Distribconf::Utils;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use MDV::Packdrakeng;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Devel::Peek;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our ($VERSION) = (qq$Revision: 232705 $ =~ /(\d+)/)[0];
10  
11 =head1 NAME
12  
13 MDV::Distribconf::Utils
14  
15 =head1 DESCRIPTION
16  
17 Contains basic functions used by Distribconf
18  
19 =head1 FUNCTIONS
20  
21 =head2 hdlist_vs_dir($hdlistfile, @dirs)
22  
23 Return two arrayrefs about rpms included only in hdlist or in directories
24  
25 =cut
26  
27 sub hdlist_vs_dir {
28 2 ▶ my ($hdlist, @dir) = @_;
Subroutine hdlist_vs_dir: called CC=18 SCAR=31.5
Pod documented
29 2 my (@only_pack, @only_dir);
30 2 my @rpms;
31 2 foreach my $dir (@dir) {
32 2 push(@rpms, glob("$dir/*.rpm"));
33 }
34 2 @rpms = sort { ($b =~ m:.*/+(.*):)[0] cmp ($a =~ m:([^/]+)$:)[0] } @rpms;
35 2 ▶ if (-f $hdlist and my $pack = MDV::Packdrakeng->open(archive => $hdlist)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $hdlist and my $pack = 'MDV::Packdrakeng'->open('archive', $hdlist)) { } 2 0 2
Condition33%1/3
-f $hdlist and my $pack = "MDV::Packdrakeng"->open("archive", $hdlist)
!ll&&!rl&&r
002
MC/DC0%0/2
-f $hdlist and my $pack = "MDV::Packdrakeng"->open("archive", $hdlist)
-f $hdlist my $pack = "MDV::Packdrakeng"->open("archive", $hdlist)
Truth table33%1/3
A and B
A= -f $hdlistB= my $pack = "MDV::Packdrakeng"->open("archive", $hdlist)
ABresult
0X0
100
111
36 2 my $hdlisttime = (stat($hdlist))[9];
37 2 my (undef, $files, undef) = $pack->getcontent();
38 2 ▶ my @hdrs = sort { $b cmp $a } map { "$_.rpm" } @{$files || []};
Branch: 1 branch
BranchTrueFalseTotal
$files or [] 0 2 2
39 2 my ($r, $h) = ("", "");
40 2 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
scalar @rpms || scalar @hdrs and do { do { my $base_r = ($r =~ m[([^/]+)$])[0] || ""; my $comp = $base_r cmp $h; my $st_d = $r ? (stat $r)[9] : 0; if ($comp < 0 or not defined $st_d) { push @only_pack, $h; } elsif ($comp > 0) { push @only_dir, $base_r; } elsif ($r and $st_d > $hdlisttime) { push @only_pack, $h; push @only_dir, ($r =~ m[.*/+(.*)])[0]; } ; if ($comp <= 0) { $h = shift @hdrs || ""; } ; if ($comp >= 0) { $r = shift @rpms || ""; } } } 2 2 4
Condition100%2/2
scalar @rpms or scalar @hdrs
l!l
22
MC/DC100%1/1
scalar @rpms or scalar @hdrs
scalar @rpms
Truth table100%2/2
A
A= scalar @rpms
Aresult
11
00
41 4 ▶ my $base_r = ($r =~ m:([^/]+)$:)[0] || '';
Condition100%2/2
($r =~ m[([^/]+)$])[0] || ''
l!l
22
MC/DC100%1/1
($r =~ m[([^/]+)$])[0] || ''
($r =~ m[([^/]+)$])[0]
Truth table100%2/2
A
A= ($r =~ m[([^/]+)$])[0]
Aresult
11
00
42 4 my $comp = ($base_r cmp $h);
43 4 ▶ my $st_d = $r ? (stat($r))[9] : 0;
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 2 2 4
44 4 ▶ if ($comp < 0 || !defined($st_d)) { push(@only_pack, $h); }
Branch: 3 branches
BranchTrueFalseTotal
if ($comp < 0 or not defined $st_d) { } 0 4 4
elsif ($comp > 0) { } 1 3 4
elsif ($r and $st_d > $hdlisttime) { } 0 5 5
Condition33%1/3
$comp < 0 or not defined $st_d
l!l&&r!l&&!r
004
MC/DC0%0/2
$comp < 0 or not defined $st_d
$comp < 0 not defined $st_d
Truth table33%1/3
A or not(B)
A= $comp < 0B= not defined $st_d
ABresult
1X1
011
000
45 1 elsif ($comp > 0) { push(@only_dir, $base_r); }
46 ▶ elsif ($r && ($st_d > $hdlisttime)) {
Condition66%2/3
$r and $st_d > $hdlisttime
!ll&&!rl&&r
210
MC/DC0%0/2
$r and $st_d > $hdlisttime
$r $st_d > $hdlisttime
Truth table66%2/3
A and B
A= $rB= $st_d > $hdlisttime
ABresult
0X0
100
111
47 0 push(@only_pack, $h);
48 0 push(@only_dir, ($r =~ m:.*/+(.*):)[0]);
49 }
50  
51 4 ▶ if ($comp <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp <= 0) 3 1 4
52 3 ▶ $h = shift(@hdrs) || '';
Condition100%2/2
shift @hdrs || ''
l!l
21
MC/DC100%1/1
shift @hdrs || ''
shift @hdrs
Truth table100%2/2
A
A= shift @hdrs
Aresult
11
00
53 }
54 4 ▶ if ($comp >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp >= 0) 4 0 4
55 4 ▶ $r = shift(@rpms) || '';
Condition50%1/2
shift @rpms || ''
l!l
40
MC/DC0%0/1
shift @rpms || ''
shift @rpms
Truth table50%1/2
A
A= shift @rpms
Aresult
11
00
56 }
57 } while (scalar(@rpms) || scalar(@hdrs));
58 } else {
59 0 return(undef, [ map { m:.*/+(.*):; $1 } @rpms ]);
60 }
61 2 return (\@only_pack, \@only_dir);
62 }
63  
64 =head2 checkmd5($md5file, @files)
65  
66 Return an array ref to unsync file found and a hashref containing
67 files and their found md5.
68  
69 =cut
70  
71 sub checkmd5 {
72 2 ▶ my ($md5file, @files) = @_;
Subroutine checkmd5: called CC=7 SCAR=19.7
Pod documented
73 2 my %foundmd5;
74 2 foreach my $file (@files) {
75 4 my ($basename) = $file =~ m:.*/+([^/]*)$:; #: vi syntax coloring
76 4 ▶ if (open(my $hfile, "<", $file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $hfile, '<', $file) { } 4 0 4
77 4 my $ctx = Digest::MD5->new;
78 4 $ctx->addfile($hfile);
79 4 close($hfile);
80 4 $foundmd5{$basename} = $ctx->hexdigest;
81 } else {
82 0 $foundmd5{$basename} = '';
83 }
84 }
85 2 ▶ open(my $hmd5, "<", $md5file) or return([ keys %foundmd5 ], \%foundmd5);
Branch: 1 branch
BranchTrueFalseTotal
open my $hmd5, "<", $md5file or return [keys %foundmd5], \%foundmd5 0 2 2
86 2 my %md5;
87 2 ▶ while (<$hmd5>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $hmd5)) 4 2 6
88 4 chomp;
89 4 s/#.*//;
90 4 ▶ /^(.{32}) (.*)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^(.{32}) (.*)/ or next 0 4 4
91 4 $md5{$2} = $1;
92 }
93 2 close($hmd5);
94 2 ▶ my @badfiles = grep { $foundmd5{$_} ne ($md5{$_} || '') } keys %foundmd5;
Condition50%1/2
$md5{$_} || ''
l!l
40
MC/DC0%0/1
$md5{$_} || ''
$md5{$_}
Truth table50%1/2
A
A= $md5{$_}
Aresult
11
00
95 2 return (\@badfiles, \%foundmd5);
96 }
97  
98 3 1;
99  
100 __END__
« Distribconf.pm ↑ Summary Distribconf/MediaCFG.pm »