line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MMM::Mirror; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
3347
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
251
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
120
|
|
5
|
4
|
|
|
4
|
|
1039
|
use URI; |
|
4
|
|
|
|
|
5802
|
|
|
4
|
|
|
|
|
113
|
|
6
|
4
|
|
|
4
|
|
1115
|
use POSIX qw(strftime); |
|
4
|
|
|
|
|
7944
|
|
|
4
|
|
|
|
|
36
|
|
7
|
4
|
|
|
4
|
|
2274
|
use MMM::Host; |
|
4
|
|
|
|
|
35
|
|
|
4
|
|
|
|
|
5663
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
MMM::Mirror |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
An object to retain per mirror information |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 METHODS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 new |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Create a MMM::Mirror object from information found in hash passed |
22
|
|
|
|
|
|
|
as arguments. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $mirror MMM::Mirror->new( url => 'rsync://host/foo/' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _rev { |
29
|
3
|
|
|
3
|
|
129
|
strftime( '%Y%m%d%H%M%S', gmtime(time) ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
33
|
5
|
|
|
5
|
1
|
1555
|
my ( $class, %infos ) = @_; |
34
|
5
|
100
|
|
|
|
27
|
$infos{url} or return; |
35
|
4
|
|
33
|
|
|
37
|
$infos{uri} ||= URI->new( $infos{url} ); |
36
|
4
|
100
|
66
|
|
|
36726
|
$infos{uri} && $infos{uri}->can('host') or return; |
37
|
3
|
|
|
|
|
1435
|
my $path = $infos{uri}->path; |
38
|
3
|
|
|
|
|
59
|
$path =~ s://*:/:g; |
39
|
3
|
50
|
|
|
|
22
|
$infos{url} = sprintf( "%s://%s%s%s", |
40
|
|
|
|
|
|
|
$infos{uri}->scheme, lc( $infos{uri}->authority ), |
41
|
|
|
|
|
|
|
$path, ( $infos{uri}->query ? '?' . $infos{uri}->query : '' ) ); |
42
|
3
|
|
|
|
|
231
|
$infos{host} = lc( $infos{uri}->host() ); |
43
|
3
|
|
33
|
|
|
114
|
$infos{hostinfo} ||= |
44
|
|
|
|
|
|
|
MMM::Host->new( %infos, hostname => $infos{uri}->host ); |
45
|
3
|
|
33
|
|
|
23
|
$infos{revision} ||= _rev(); |
46
|
3
|
|
|
|
|
33
|
bless( {%infos}, $class ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 url |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Return the url of the mirror |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub url { |
56
|
1
|
|
|
1
|
1
|
2
|
my ($self) = @_; |
57
|
1
|
|
|
|
|
6
|
$self->{url}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 host |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Return the hostname of the mirror found in url |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub host { |
67
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
68
|
0
|
|
|
|
|
0
|
return $self->{host}; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 level |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Return the level of this mirror in mirrors hierarchy |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub level { |
78
|
2
|
|
|
2
|
1
|
7
|
my ($self) = @_; |
79
|
2
|
50
|
|
|
|
12
|
defined( $self->{level} ) ? $self->{level} : 3; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 frequency |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Period in minutes between sync performed by this mirror |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub frequency { |
89
|
2
|
|
|
2
|
1
|
6
|
my ($self) = @_; |
90
|
2
|
50
|
|
|
|
266
|
$self->{frequency} || 120; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 source |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Return the mirror source name from which this mirror is part of. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub source { |
100
|
2
|
|
|
2
|
1
|
486
|
my ($self) = @_; |
101
|
2
|
|
|
|
|
45
|
$self->{source}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 set_source($source) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Set the source name for this mirror. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub set_source { |
111
|
1
|
|
|
1
|
1
|
3
|
my ( $self, $source ) = @_; |
112
|
1
|
|
|
|
|
6
|
$self->{source} = $source; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 hostinfo |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Return a MMM::Host object proper to the mirror if any |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub hostinfo { |
122
|
2
|
|
|
2
|
1
|
4
|
my ($self) = @_; |
123
|
2
|
|
|
|
|
14
|
return $self->{hostinfo}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 get_geo |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Load host geo info if any |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub get_geo { |
133
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
134
|
0
|
0
|
|
|
|
0
|
if($self->{hostinfo}->get_geo()) { |
135
|
0
|
|
|
|
|
0
|
return 1; |
136
|
|
|
|
|
|
|
} else { |
137
|
0
|
|
|
|
|
0
|
return; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 random |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Return a cached random value assigned to this mirror. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=cut |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub random { |
148
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
149
|
0
|
|
0
|
|
|
0
|
$self->{random} ||= rand(); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head2 info |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Return textual information about this mirror |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub info { |
159
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
160
|
|
|
|
|
|
|
return |
161
|
0
|
|
|
|
|
0
|
sprintf( '%s (%d/%d)', $self->{url}, $self->level, $self->frequency ); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head2 revision |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Return the revision of the entry. The revision is an id to identify if an |
167
|
|
|
|
|
|
|
entry is newer than another for same mirror. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub revision { |
172
|
5
|
|
|
5
|
1
|
8
|
my ($self) = @_; |
173
|
5
|
|
|
|
|
30
|
$self->{revision}; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 refresh_revision |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Reset revision to current timestamp |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
sub refresh_revision { |
183
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
184
|
0
|
|
|
|
|
0
|
$self->{revision} = _rev(); |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 same_mirror($mirror) |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Compare this mirror with another and return 1 if both entries refer to same |
190
|
|
|
|
|
|
|
mirror |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub same_mirror { |
195
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $mirror ) = @_; |
196
|
0
|
0
|
0
|
|
|
0
|
if ( $self->host eq $mirror->host && $self->source eq $mirror->source ) { |
197
|
0
|
|
|
|
|
0
|
return 1; |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
0
|
return; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 sync_mirror($mirror) |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Get unknown values from $mirror if defined. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub sync_mirror { |
209
|
1
|
|
|
1
|
1
|
7
|
my ( $self, $mirror ) = @_; |
210
|
1
|
|
|
|
|
4
|
foreach (qw(level frequency)) { |
211
|
2
|
100
|
33
|
|
|
16
|
if ( |
|
|
|
66
|
|
|
|
|
212
|
|
|
|
|
|
|
( !defined( $self->{$_} ) ) |
213
|
|
|
|
|
|
|
|| ( defined( $mirror->{$_} ) |
214
|
|
|
|
|
|
|
&& $mirror->revision > $self->revision ) |
215
|
|
|
|
|
|
|
) |
216
|
|
|
|
|
|
|
{ |
217
|
1
|
|
|
|
|
5
|
$self->{$_} = $mirror->{$_}; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
} |
220
|
1
|
50
|
33
|
|
|
9
|
if ( $self->{hostinfo} && $mirror->{hostinfo} ) { |
221
|
1
|
|
|
|
|
8
|
$self->{hostinfo}->sync_host( $mirror->{hostinfo} ); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
else { |
224
|
0
|
|
0
|
|
|
0
|
$self->{hostinfo} ||= $mirror->{hostinfo}; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
1
|
50
|
|
|
|
5
|
if ( $mirror->revision > $self->revision ) { |
228
|
0
|
|
|
|
|
|
$self->{revision} = $mirror->{revision}; |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=head2 xml_output |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
Return a xml string describing this mirror. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
See also |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=cut |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub xml_output { |
241
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
242
|
0
|
|
|
|
|
|
my $xml = "\t\t\n"; |
243
|
|
|
|
|
|
|
|
244
|
0
|
|
|
|
|
|
foreach (qw(url level frequency revision)) { |
245
|
0
|
0
|
|
|
|
|
if ( defined( $self->{$_} ) ) { |
246
|
0
|
|
|
|
|
|
$xml .= sprintf( "\t\t\t<%s>%s%s>\n", $_, $self->{$_}, $_ ); |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
} |
249
|
0
|
|
|
|
|
|
foreach (qw(password ssh)) { |
250
|
0
|
0
|
|
|
|
|
if ( $self->{$_} ) { |
251
|
0
|
|
|
|
|
|
$xml .= sprintf( "\t\t\t<%s>%s%s>\n", $_, $self->{$_}, $_ ); |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
0
|
|
|
|
|
|
$xml .= "\t\t\n"; |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
|
|
|
$xml; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1; |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 AUTHOR |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
Olivier Thauvin |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Copyright (C) 2006 Olivier Thauvin |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
271
|
|
|
|
|
|
|
modify it under the terms of the GNU General Public License |
272
|
|
|
|
|
|
|
as published by the Free Software Foundation; either version 2 |
273
|
|
|
|
|
|
|
of the License, or (at your option) any later version. |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
276
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
277
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
278
|
|
|
|
|
|
|
GNU General Public License for more details. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
281
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
282
|
|
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
=cut |
285
|
|
|
|
|
|
|
|