line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package urpm::md5sum; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1429
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
4
|
use urpm::util qw(cat_ file_size); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
5
|
1
|
|
|
1
|
|
27
|
use urpm::msg; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
urpm::md5sum - Meta-data checking routines for urpmi |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=over |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=cut |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=item parse($md5sum_file) |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Parse a MD5SUM file. |
24
|
|
|
|
|
|
|
Returns a hash of file => md5sum |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub parse { |
29
|
|
|
|
|
|
|
my ($md5sum_file) = @_; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my %h = map { |
32
|
|
|
|
|
|
|
my ($md5sum, $file) = m|^([0-9-a-f]+)\s+(?:\./)?(\S+)$|i or return; |
33
|
|
|
|
|
|
|
$file => $md5sum; |
34
|
|
|
|
|
|
|
} cat_($md5sum_file) or return; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
\%h; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item parse($md5sum_file) |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Check size and parse a MD5SUM file. |
43
|
|
|
|
|
|
|
Returns a hash of file => md5sum |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub check_file { |
48
|
|
|
|
|
|
|
my ($md5sum_file) = @_; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
file_size($md5sum_file) > 32 && parse($md5sum_file); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub from_MD5SUM__or_warn { |
54
|
|
|
|
|
|
|
my ($urpm, $md5sums, $basename) = @_; |
55
|
|
|
|
|
|
|
$md5sums->{$basename} or $urpm->{log}(N("warning: md5sum for %s unavailable in MD5SUM file", $basename)); |
56
|
|
|
|
|
|
|
$md5sums->{$basename}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item versioned_media_info_file($urpm, $medium, $basename) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the latest versionated file name for $basename |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub versioned_media_info_file { |
67
|
|
|
|
|
|
|
my ($urpm, $medium, $basename) = @_; |
68
|
|
|
|
|
|
|
my $md5sums = $medium->{parsed_md5sum} or $urpm->{log}("$medium->{name} has no md5sum"), return; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my @l = map { $md5sums->{$_} eq $md5sums->{$basename} && /^(\d{8}-\d{6})-\Q$basename\E$/ ? $1 : @{[]} } keys %$md5sums; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
if (@l == 0) { |
73
|
|
|
|
|
|
|
$urpm->{debug}("no versioned $basename for medium $medium->{name}") if $urpm->{debug}; |
74
|
|
|
|
|
|
|
} else { |
75
|
|
|
|
|
|
|
@l > 1 and $urpm->{debug}("multiple versions for $basename for medium $medium->{name}: @l") if $urpm->{debug}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
$l[0]; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item compute($file) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Return the MD5SUM control sum of $file |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub compute { |
87
|
|
|
|
|
|
|
my ($file) = @_; |
88
|
|
|
|
|
|
|
eval { require Digest::MD5 }; |
89
|
|
|
|
|
|
|
if ($@) { |
90
|
|
|
|
|
|
|
#- Use an external command to avoid depending on perl |
91
|
|
|
|
|
|
|
return (split ' ', `/usr/bin/md5sum '$file'`)[0]; |
92
|
|
|
|
|
|
|
} else { |
93
|
|
|
|
|
|
|
my $ctx = Digest::MD5->new; |
94
|
|
|
|
|
|
|
open my $fh, $file or return ''; |
95
|
|
|
|
|
|
|
$ctx->addfile($fh); |
96
|
|
|
|
|
|
|
close $fh; |
97
|
|
|
|
|
|
|
return $ctx->hexdigest; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Copyright (C) 2005 MandrakeSoft SA |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Copyright (C) 2005-2010 Mandriva SA |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright (C) 2011-2017 Mageia |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |