line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MDV::Distribconf::Utils; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
15
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
166
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
5
|
3
|
|
|
3
|
|
15
|
use MDV::Packdrakeng; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
49
|
|
6
|
3
|
|
|
3
|
|
13
|
use Digest::MD5; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
140
|
|
7
|
3
|
|
|
3
|
|
6271
|
use Devel::Peek; |
|
3
|
|
|
|
|
1894
|
|
|
3
|
|
|
|
|
21
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
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
|
|
|
2
|
1
|
6
|
my ($hdlist, @dir) = @_; |
29
|
2
|
|
|
|
|
2
|
my (@only_pack, @only_dir); |
30
|
0
|
|
|
|
|
0
|
my @rpms; |
31
|
2
|
|
|
|
|
12
|
foreach my $dir (@dir) { |
32
|
2
|
|
|
|
|
240
|
push(@rpms, glob("$dir/*.rpm")); |
33
|
|
|
|
|
|
|
} |
34
|
2
|
|
|
|
|
12
|
@rpms = sort { ($b =~ m:.*/+(.*):)[0] cmp ($a =~ m:([^/]+)$:)[0] } @rpms; |
|
2
|
|
|
|
|
24
|
|
35
|
2
|
50
|
33
|
|
|
44
|
if (-f $hdlist and my $pack = MDV::Packdrakeng->open(archive => $hdlist)) { |
36
|
2
|
|
|
|
|
72042
|
my $hdlisttime = (stat($hdlist))[9]; |
37
|
2
|
|
|
|
|
15
|
my (undef, $files, undef) = $pack->getcontent(); |
38
|
2
|
50
|
|
|
|
52
|
my @hdrs = sort { $b cmp $a } map { "$_.rpm" } @{$files || []}; |
|
1
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
10
|
|
39
|
2
|
|
|
|
|
6
|
my ($r, $h) = ("", ""); |
40
|
2
|
|
100
|
|
|
3
|
do { |
41
|
4
|
|
100
|
|
|
29
|
my $base_r = ($r =~ m:([^/]+)$:)[0] || ''; |
42
|
4
|
|
|
|
|
5
|
my $comp = ($base_r cmp $h); |
43
|
4
|
100
|
|
|
|
37
|
my $st_d = $r ? (stat($r))[9] : 0; |
44
|
4
|
50
|
33
|
|
|
33
|
if ($comp < 0 || !defined($st_d)) { push(@only_pack, $h); } |
|
0
|
100
|
66
|
|
|
0
|
|
|
|
50
|
|
|
|
|
|
45
|
1
|
|
|
|
|
3
|
elsif ($comp > 0) { push(@only_dir, $base_r); } |
46
|
|
|
|
|
|
|
elsif ($r && ($st_d > $hdlisttime)) { |
47
|
0
|
|
|
|
|
0
|
push(@only_pack, $h); |
48
|
0
|
|
|
|
|
0
|
push(@only_dir, ($r =~ m:.*/+(.*):)[0]); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
4
|
100
|
|
|
|
9
|
if ($comp <= 0) { |
52
|
3
|
|
100
|
|
|
9
|
$h = shift(@hdrs) || ''; |
53
|
|
|
|
|
|
|
} |
54
|
4
|
50
|
|
|
|
9
|
if ($comp >= 0) { |
55
|
4
|
|
50
|
|
|
29
|
$r = shift(@rpms) || ''; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} while (scalar(@rpms) || scalar(@hdrs)); |
58
|
|
|
|
|
|
|
} else { |
59
|
0
|
|
|
|
|
0
|
return(undef, [ map { m:.*/+(.*):; $1 } @rpms ]); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
} |
61
|
2
|
|
|
|
|
13
|
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
|
|
|
2
|
1
|
6
|
my ($md5file, @files) = @_; |
73
|
2
|
|
|
|
|
4
|
my %foundmd5; |
74
|
2
|
|
|
|
|
3
|
foreach my $file (@files) { |
75
|
4
|
|
|
|
|
22
|
my ($basename) = $file =~ m:.*/+([^/]*)$:; #: vi syntax coloring |
76
|
4
|
50
|
|
|
|
160
|
if (open(my $hfile, "<", $file)) { |
77
|
4
|
|
|
|
|
25
|
my $ctx = Digest::MD5->new; |
78
|
4
|
|
|
|
|
77
|
$ctx->addfile($hfile); |
79
|
4
|
|
|
|
|
36
|
close($hfile); |
80
|
4
|
|
|
|
|
39
|
$foundmd5{$basename} = $ctx->hexdigest; |
81
|
|
|
|
|
|
|
} else { |
82
|
0
|
|
|
|
|
0
|
$foundmd5{$basename} = ''; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
} |
85
|
2
|
50
|
|
|
|
64
|
open(my $hmd5, "<", $md5file) or return([ keys %foundmd5 ], \%foundmd5); |
86
|
2
|
|
|
|
|
3
|
my %md5; |
87
|
2
|
|
|
|
|
21
|
while (<$hmd5>) { |
88
|
4
|
|
|
|
|
5
|
chomp; |
89
|
4
|
|
|
|
|
6
|
s/#.*//; |
90
|
4
|
50
|
|
|
|
14
|
/^(.{32}) (.*)/ or next; |
91
|
4
|
|
|
|
|
25
|
$md5{$2} = $1; |
92
|
|
|
|
|
|
|
} |
93
|
2
|
|
|
|
|
17
|
close($hmd5); |
94
|
2
|
|
50
|
|
|
6
|
my @badfiles = grep { $foundmd5{$_} ne ($md5{$_} || '') } keys %foundmd5; |
|
4
|
|
|
|
|
14
|
|
95
|
2
|
|
|
|
|
11
|
return (\@badfiles, \%foundmd5); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
1; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
__END__ |