blib/lib/File/Rsync/Mirror/Recentfile.pm

filter: Statementstmt 56.7% 578 / 1019 Branchbran 43.1% 220 / 510 Conditioncond 48.1% 92 / 191 MC/DCmcdc 27.8% 32 / 115 Subroutinesub 72.4% 63 / 87 Podpod 100% 39 / 39 totaltotal 52.2% 1024 / 1961 CC 341 SCAR 38.0
CC
341
Cov
52%
mirror_path
210.0
_mirror_item
182.0
uptodate
156.0
CRAP 44.7
« blib/lib/File/Rsync/Mirror/Recent.pm ↑ Summary bin/rrr-fsck »
1 package File::Rsync::Mirror::Recentfile;
2  
3 # use warnings;
4 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 File::Rsync::Mirror::Recentfile - mirroring via rsync made efficient
11  
12 =cut
13  
14 14 my $HAVE = {};
15 14 for my $package (
16 "Data::Serializer",
17 "File::Rsync"
18 ) {
19 28 $HAVE->{$package} = eval qq{ require $package; };
20 }
21 14 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 14 ▶use File::Basename qw(basename dirname fileparse);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 14 ▶use File::Copy qw(cp);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 14 ▶use File::Path qw(mkpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 14 ▶use File::Rsync::Mirror::Recentfile::FakeBigFloat qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 14 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 14 ▶use List::Util qw(first max min);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 14 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 14 ▶use Storable;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 14 ▶use Time::HiRes qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
31 14 ▶use YAML::Syck;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 14 ▶use version; our $VERSION = qv('0.0.9');
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 14 ▶use constant MAX_INT => ~0>>1; # anything better?
Subroutine BEGIN: called CC=1 SCAR=0.0
36 14 ▶use constant DEFAULT_PROTOCOL => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 # cf. interval_secs
39 14 my %seconds;
40  
41 # maybe subclass if this mapping is bad?
42 my %serializers;
43  
44 =head1 SYNOPSIS
45  
46 Writer (of a single file):
47  
48 use File::Rsync::Mirror::Recentfile;
49 my $fr = File::Rsync::Mirror::Recentfile->new
50 (
51 interval => q(6h),
52 filenameroot => "RECENT",
53 comment => "These 'RECENT' files are part of a test of a new CPAN mirroring concept. Please ignore them for now.",
54 localroot => "/home/ftp/pub/PAUSE/authors/",
55 aggregator => [qw(1d 1W 1M 1Q 1Y Z)],
56 );
57 $rf->update("/home/ftp/pub/PAUSE/authors/id/A/AN/ANDK/CPAN-1.92_63.tar.gz","new");
58  
59 Reader/mirrorer:
60  
61 my $rf = File::Rsync::Mirror::Recentfile->new
62 (
63 filenameroot => "RECENT",
64 interval => q(6h),
65 localroot => "/home/ftp/pub/PAUSE/authors",
66 remote_dir => "",
67 remote_host => "pause.perl.org",
68 remote_module => "authors",
69 rsync_options => {
70 compress => 1,
71 'rsync-path' => '/usr/bin/rsync',
72 links => 1,
73 times => 1,
74 'omit-dir-times' => 1,
75 checksum => 1,
76 },
77 verbose => 1,
78 );
79 $rf->mirror;
80  
81 Aggregator (usually the writer):
82  
83 my $rf = File::Rsync::Mirror::Recentfile->new_from_file ( $file );
84 $rf->aggregate;
85  
86 =head1 DESCRIPTION
87  
88 Lower level than F:R:M:Recent, handles one recentfile. Whereas a tree
89 is always composed of several recentfiles, controlled by the
90 F:R:M:Recent object. The Recentfile object has to do the bookkeeping
91 for a single timeslice.
92  
93 =head1 EXPORT
94  
95 No exports.
96  
97 =head1 CONSTRUCTORS / DESTRUCTOR
98  
99 =head2 my $obj = CLASS->new(%hash)
100  
101 Constructor. On every argument pair the key is a method name and the
102 value is an argument to that method name.
103  
104 If a recentfile for this resource already exists, metadata that are
105 not defined by the constructor will be fetched from there as soon as
106 it is being read by recent_events().
107  
108 =cut
109  
110 110 ▶sub new {
Subroutine new: called CC=5 SCAR=16.1
Pod documented
111 110 my($class, @args) = @_;
112 110 my $self = bless {}, $class;
113 110 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 336 110 446
114 336 my($method,$arg) = splice @args, 0, 2;
115 336 $self->$method($arg);
116 }
117 110 ▶ unless (defined $self->protocol) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->protocol) 110 0 110
118 110 $self->protocol(DEFAULT_PROTOCOL);
119 }
120 110 ▶ unless (defined $self->filenameroot) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->filenameroot) 105 5 110
121 105 $self->filenameroot("RECENT");
122 }
123 110 ▶ unless (defined $self->serializer_suffix) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->serializer_suffix) 106 4 110
124 106 $self->serializer_suffix(".yaml");
125 }
126 110 return $self;
127 }
128  
129 =head2 my $obj = CLASS->new_from_file($file)
130  
131 Constructor. $file is a I<recentfile>.
132  
133 =cut
134  
135 211 ▶sub new_from_file {
Subroutine new_from_file: called CC=10 SCAR=24.4
Pod documented
136 211 my($class, $file) = @_;
137 211 my $self = bless {}, $class;
138 211 $self->_rfile($file);
139 #?# $self->lock;
140 211 ▶ my $serialized = do { open my $fh, $file or die "Could not open '$file': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $file or die "Could not open '${file}': $!" 211 0 211
141 211 local $/;
142 211 <$fh>;
143 };
144 # XXX: we can skip this step when the metadata are sufficient, but
145 # we cannot parse the file without some magic stuff about
146 # serialized formats
147 211 ▶ while (-l $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $file) 6 211 217
148 6 my($name,$path) = fileparse $file;
149 6 my $symlink = readlink $file;
150 6 ▶ if ($symlink =~ m|/|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symlink =~ m[/]) 0 6 6
151 0 die "FIXME: filenames containing '/' not supported, got $symlink";
152 }
153 6 $file = File::Spec->catfile ( $path, $symlink );
154 }
155 211 my($name,$path,$suffix) = fileparse $file, keys %serializers;
156 211 $self->serializer_suffix($suffix);
157 211 $self->localroot($path);
158 211 ▶ die "Could not determine file format from suffix" unless $suffix;
Branch: 1 branch
BranchTrueFalseTotal
unless $suffix 0 211 211
159 211 my $deserialized;
160 211 ▶ if ($suffix eq ".yaml") {
Branch: 2 branches
BranchTrueFalseTotal
if ($suffix eq '.yaml') { } 211 0 211
elsif ($HAVE->{'Data::Serializer'}) { } 0 0 0
161 211 require YAML::Syck;
162 211 $deserialized = YAML::Syck::LoadFile($file);
163 } elsif ($HAVE->{"Data::Serializer"}) {
164 my $serializer = Data::Serializer->new
165 0 ( serializer => $serializers{$suffix} );
166 0 $deserialized = $serializer->raw_deserialize($serialized);
167 } else {
168 0 die "Data::Serializer not installed, cannot proceed with suffix '$suffix'";
169 }
170 211 ▶ while (my($k,$v) = each %{$deserialized->{meta}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$deserialized{"meta"};}) 2297 211 2508
171 2297 ▶ next if $k ne lc $k; # "Producers"
Branch: 1 branch
BranchTrueFalseTotal
if $k ne lc $k 211 2086 2297
172 2086 $self->$k($v);
173 }
174 211 ▶ unless (defined $self->protocol) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->protocol) 0 211 211
175 0 $self->protocol(DEFAULT_PROTOCOL);
176 }
177 211 return $self;
178 }
179  
180 =head2 DESTROY
181  
182 A simple unlock.
183  
184 =cut
185 992 ▶sub DESTROY {
Subroutine DESTROY: called CC=4 SCAR=14.1
186 992 my $self = shift;
187 992 $self->unlock;
188 992 ▶ unless ($self->_current_tempfile_fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_current_tempfile_fh) 992 0 992
189 992 ▶ if (my $tempfile = $self->_current_tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tempfile = $self->_current_tempfile) 1 991 992
190 1 ▶ if (-e $tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $tempfile) 1 0 1
191 # unlink $tempfile; # may fail in global destruction
192 }
193 }
194 }
195 }
196  
197 =head1 ACCESSORS
198  
199 =cut
200  
201 14 my @accessors;
202  
203 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
204 14 @accessors = (
205 "_current_tempfile",
206 "_current_tempfile_fh",
207 "_delayed_operations",
208 "_done",
209 "_interval",
210 "_is_locked",
211 "_localroot",
212 "_merged",
213 "_pathdb",
214 "_remember_last_uptodate_call",
215 "_remote_dir",
216 "_remoteroot",
217 "_requires_fsck",
218 "_rfile",
219 "_rsync",
220 "__verified_tempdir",
221 "_seeded",
222 "_uptodateness_ever_reached",
223 "_use_tempfile",
224 );
225  
226 14 my @pod_lines =
227 14 split /\n/, <<'=cut'; push @accessors, grep {s/^=item\s+//} @pod_lines; }
228  
229 =over 4
230  
231 =item aggregator
232  
233 A list of interval specs that tell the aggregator which I<recentfile>s
234 are to be produced.
235  
236 =item canonize
237  
238 The name of a method to canonize the path before rsyncing. Only
239 supported value is C<naive_path_normalize>. Defaults to that.
240  
241 =item comment
242  
243 A comment about this tree and setup.
244  
245 =item dirtymark
246  
247 A timestamp. The dirtymark is updated whenever an out of band change
248 on the origin server is performed that violates the protocol. Say,
249 they add or remove files in the middle somewhere. Slaves must react
250 with a devaluation of their C<done> structure which then leads to a
251 full re-sync of all files. Implementation note: dirtymark may increase
252 or decrease.
253  
254 =item filenameroot
255  
256 The (prefix of the) filename we use for this I<recentfile>. Defaults to
257 C<RECENT>. The string must not contain a directory separator.
258  
259 =item have_mirrored
260  
261 Timestamp remembering when we mirrored this recentfile the last time.
262 Only relevant for slaves.
263  
264 =item ignore_link_stat_errors
265  
266 If set to true, rsync errors are ignored that complain about link stat
267 errors. These seem to happen only when there are files missing at the
268 origin. In race conditions this can always happen, so it defaults to
269 true.
270  
271 =item is_slave
272  
273 If set to true, this object will fetch a new recentfile from remote
274 when the timespan between the last mirror (see have_mirrored) and now
275 is too large (see C<ttl>).
276  
277 =item keep_delete_objects_forever
278  
279 The default for delete events is that they are passed through the
280 collection of recentfile objects until they reach the Z file. There
281 they get dropped so that the associated file object ceases to exist at
282 all. By setting C<keep_delete_objects_forever> the delete objects are
283 kept forever. This makes the Z file larger but has the advantage that
284 slaves that have interrupted mirroring for a long time still can clean
285 up their copy.
286  
287 =item locktimeout
288  
289 After how many seconds shall we die if we cannot lock a I<recentfile>?
290 Defaults to 600 seconds.
291  
292 =item loopinterval
293  
294 When mirror_loop is called, this accessor can specify how much time
295 every loop shall at least take. If the work of a loop is done before
296 that time has gone, sleeps for the rest of the time. Defaults to
297 arbitrary 42 seconds.
298  
299 =item max_files_per_connection
300  
301 Maximum number of files that are transferred on a single rsync call.
302 Setting it higher means higher performance at the price of holding
303 connections longer and potentially disturbing other users in the pool.
304 Defaults to the arbitrary value 42.
305  
306 =item max_rsync_errors
307  
308 When rsync operations encounter that many errors without any resetting
309 success in between, then we die. Defaults to unlimited. A value of
310 -1 means we run forever ignoring all rsync errors.
311  
312 =item minmax
313  
314 Hashref remembering when we read the recent_events from this file the
315 last time and what the timespan was.
316  
317 =item protocol
318  
319 When the RECENT file format changes, we increment the protocol. We try
320 to support older protocols in later releases.
321  
322 =item remote_host
323  
324 The host we are mirroring from. Leave empty for the local filesystem.
325  
326 =item remote_module
327  
328 Rsync servers have so called modules to separate directory trees from
329 each other. Put here the name of the module under which we are
330 mirroring. Leave empty for local filesystem.
331  
332 =item rsync_options
333  
334 Things like compress, links, times or checksums. Passed in to the
335 File::Rsync object used to run the mirror.
336  
337 =item serializer_suffix
338  
339 Mostly untested accessor. The only well tested format for
340 I<recentfile>s at the moment is YAML. It is used with YAML::Syck via
341 Data::Serializer. But in principle other formats are supported as
342 well. See section SERIALIZERS below.
343  
344 =item sleep_per_connection
345  
346 Sleep that many seconds (floating point OK) after every chunk of rsyncing
347 has finished. Defaults to arbitrary 0.42.
348  
349 =item tempdir
350  
351 Directory to write temporary files to. Must allow rename operations
352 into the tree which usually means it must live on the same partition
353 as the target directory. Defaults to C<< $self->localroot >>.
354  
355 =item ttl
356  
357 Time to live. Number of seconds after which this recentfile must be
358 fetched again from the origin server. Only relevant for slaves.
359 Defaults to arbitrary 24.2 seconds.
360  
361 =item verbose
362  
363 Boolean to turn on a bit verbosity.
364  
365 =item verboselog
366  
367 Path to the logfile to write verbose progress information to. This is
368 a primitive stop gap solution to get simple verbose logging working.
369 Switching to Log4perl or similar is probably the way to go.
370  
371 =back
372  
373 =cut
374  
375 14 ▶use accessors @accessors;
Subroutine BEGIN: called CC=1 SCAR=0.0
376  
377 =head1 METHODS
378  
379 =head2 (void) $obj->aggregate( %options )
380  
381 Takes all intervals that are collected in the accessor called
382 aggregator. Sorts them by actual length of the interval.
383 Removes those that are shorter than our own interval. Then merges this
384 object into the next larger object. The merging continues upwards
385 as long as the next I<recentfile> is old enough to warrant a merge.
386  
387 If a merge is warranted is decided according to the interval of the
388 previous interval so that larger files are not so often updated as
389 smaller ones. If $options{force} is true, all files get updated.
390  
391 Here is an example to illustrate the behaviour. Given aggregators
392  
393 1h 1d 1W 1M 1Q 1Y Z
394  
395 then
396  
397 1h updates 1d on every call to aggregate()
398 1d updates 1W earliest after 1h
399 1W updates 1M earliest after 1d
400 1M updates 1Q earliest after 1W
401 1Q updates 1Y earliest after 1M
402 1Y updates Z earliest after 1Q
403  
404 Note that all but the smallest recentfile get updated at an arbitrary
405 rate and as such are quite useless on their own.
406  
407 =cut
408  
409 70 ▶sub aggregate {
Subroutine aggregate: called CC=9 SCAR=22.0
Pod documented
410 70 my($self, %option) = @_;
411 70 my %seen_interval;
412 580 my @aggs = sort { $a->{secs} <=> $b->{secs} }
413 370 ▶ grep { !$seen_interval{$_->{interval}}++ && $_->{secs} >= $self->interval_secs }
Condition33%1/3
!$seen_interval{$_->{'interval'}}++ && $_->{'secs'} >= $self->interval_secs
!ll&&!rl&&r
00370
MC/DC0%0/2
!$seen_interval{$_->{'interval'}}++ && $_->{'secs'} >= $self->interval_secs
!$seen_interval{$_->{'interval'}}++ $_->{'secs'} >= $self->interval_secs
Truth table33%1/3
not(A) && B
A= !$seen_interval{$_->{'interval'}}++B= $_->{'secs'} >= $self->interval_secs
ABresult
0X0
100
111
414 370 map { { interval => $_, secs => $self->interval_secs($_)} }
415 70 ▶ $self->interval, @{$self->aggregator || []};
Condition50%1/2
$self->aggregator || []
l!l
700
MC/DC0%0/1
$self->aggregator || []
$self->aggregator
Truth table50%1/2
A
A= $self->aggregator
Aresult
11
00
416 70 $self->update;
417 70 $aggs[0]{object} = $self;
418 70 AGGREGATOR: for my $i (0..$#aggs-1) {
419 194 my $this = $aggs[$i]{object};
420 194 my $next = $this->_sparse_clone;
421 194 $next->interval($aggs[$i+1]{interval});
422 194 my $want_merge = 0;
423 194 ▶ if ($option{force} || $i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option{'force'} or $i == 0) { } 118 76 194
Condition100%3/3
$option{"force"} or $i == 0
l!l&&r!l&&!r
605876
MC/DC100%2/2
$option{"force"} or $i == 0
$option{"force"} $i == 0
Truth table100%3/3
A or B
A= $option{"force"}B= $i == 0
ABresult
1X1
011
000
424 118 $want_merge = 1;
425 } else {
426 76 my $next_rfile = $next->rfile;
427 76 ▶ if (-e $next_rfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $next_rfile) { } 64 12 76
428 64 my $prev = $aggs[$i-1]{object};
429 64 local $^T = time;
430 64 my $next_age = 86400 * -M $next_rfile;
431 64 ▶ if ($next_age > $prev->interval_secs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_age > $prev->interval_secs) 11 53 64
432 11 $want_merge = 1;
433 }
434 } else {
435 12 $want_merge = 1;
436 }
437 }
438 194 ▶ if ($want_merge) {
Branch: 1 branch
BranchTrueFalseTotal
if ($want_merge) { } 141 53 194
439 141 $next->merge($this);
440 141 $aggs[$i+1]{object} = $next;
441 } else {
442 53 last AGGREGATOR;
443 }
444 }
445 }
446  
447 # collect file size and mtime for all files of this aggregate
448 6 ▶sub _debug_aggregate {
Subroutine _debug_aggregate: called CC=3 SCAR=11.0
449 6 my($self) = @_;
450 54 my @aggs = sort { $a->{secs} <=> $b->{secs} }
451 36 map { { interval => $_, secs => $self->interval_secs($_)} }
452 6 ▶ $self->interval, @{$self->aggregator || []};
Condition50%1/2
$self->aggregator || []
l!l
60
MC/DC0%0/1
$self->aggregator || []
$self->aggregator
Truth table50%1/2
A
A= $self->aggregator
Aresult
11
00
453 6 my $report = [];
454 6 for my $i (0..$#aggs) {
455 36 my $this = Storable::dclone $self;
456 36 $this->interval($aggs[$i]{interval});
457 36 my $rfile = $this->rfile;
458 36 my @stat = stat $rfile;
459 36 push @$report, {rfile => $rfile, size => $stat[7], mtime => $stat[9]};
460 }
461 6 $report;
462 }
463  
464 # (void) $self->_assert_symlink()
465 330 ▶sub _assert_symlink {
Subroutine _assert_symlink: called CC=10 SCAR=26.0
466 330 my($self) = @_;
467 330 my $recentrecentfile = File::Spec->catfile
468 (
469 $self->localroot,
470 sprintf
471 (
472 "%s.recent",
473 $self->filenameroot
474 )
475 );
476 330 ▶ if ($Config{d_symlink} eq "define") {
Branch: 1 branch
BranchTrueFalseTotal
if ($File::Rsync::Mirror::Recentfile::Config{'d_symlink'} eq 'define') { } 330 0 330
477 330 my $howto_create_symlink; # 0=no need; 1=straight symlink; 2=rename symlink
478 330 ▶ if (-l $recentrecentfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-l $recentrecentfile) { } 325 5 330
479 325 my $found_symlink = readlink $recentrecentfile;
480 325 ▶ if ($found_symlink eq $self->rfilename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found_symlink eq $self->rfilename) { } 321 4 325
481 321 return;
482 } else {
483 4 $howto_create_symlink = 2;
484 }
485 } else {
486 5 $howto_create_symlink = 1;
487 }
488 9 ▶ if (1 == $howto_create_symlink) {
Branch: 1 branch
BranchTrueFalseTotal
if (1 == $howto_create_symlink) { } 5 4 9
489 5 ▶ symlink $self->rfilename, $recentrecentfile or die "Could not create symlink '$recentrecentfile': $!"
Branch: 1 branch
BranchTrueFalseTotal
symlink $self->rfilename, $recentrecentfile or die "Could not create symlink '${recentrecentfile}': $!" 5 0 5
490 } else {
491 4 unlink "$recentrecentfile.$$"; # may fail
492 4 ▶ symlink $self->rfilename, "$recentrecentfile.$$" or die "Could not create symlink '$recentrecentfile.$$': $!";
Branch: 1 branch
BranchTrueFalseTotal
symlink $self->rfilename, "$recentrecentfile.${$}" or die "Could not create symlink '$recentrecentfile.${$}': $!" 4 0 4
493 4 ▶ rename "$recentrecentfile.$$", $recentrecentfile or die "Could not rename '$recentrecentfile.$$' to $recentrecentfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename "$recentrecentfile.${$}", $recentrecentfile or die "Could not rename '$recentrecentfile.${$}' to ${recentrecentfile}: $!" 4 0 4
494 }
495 } else {
496 0 warn "Warning: symlinks not supported on this system, doing a copy instead\n";
497 0 unlink "$recentrecentfile.$$"; # may fail
498 0 ▶ cp $self->rfilename, "$recentrecentfile.$$" or die "Could not copy to '$recentrecentfile.$$': $!";
Branch: 1 branch
BranchTrueFalseTotal
cp($self->rfilename, "$recentrecentfile.${$}") or die "Could not copy to '$recentrecentfile.${$}': $!" 0 0 0
499 0 ▶ rename "$recentrecentfile.$$", $recentrecentfile or die "Could not rename '$recentrecentfile.$$' to $recentrecentfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
rename "$recentrecentfile.${$}", $recentrecentfile or die "Could not rename '$recentrecentfile.${$}' to ${recentrecentfile}: $!" 0 0 0
500 }
501 }
502  
503 =head2 $hashref = $obj->delayed_operations
504  
505 A hash of hashes containing unlink and rmdir operations which had to
506 wait until the recentfile got unhidden in order to not confuse
507 downstream mirrors (in case we have some).
508  
509 =cut
510  
511 0 ▶sub delayed_operations {
Subroutine delayed_operations: not called CC=2 SCAR=17.9
Pod documented
512 0 my($self) = @_;
513 0 my $x = $self->_delayed_operations;
514 0 ▶ unless (defined $x) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $x) 0 0 0
515 0 $x = {
516 unlink => {},
517 rmdir => {},
518 };
519 0 $self->_delayed_operations ($x);
520 }
521 0 return $x;
522 }
523  
524 =head2 $done = $obj->done
525  
526 C<$done> is a reference to a L<File::Rsync::Mirror::Recentfile::Done>
527 object that keeps track of rsync activities. Only needed and used when
528 we are a mirroring slave.
529  
530 =cut
531  
532 1 ▶sub done {
Subroutine done: called CC=3 SCAR=14.2
Pod documented
533 1 my($self) = @_;
534 1 require File::Rsync::Mirror::Recentfile::Done;
535 1 my $done = $self->_done;
536 1 ▶ if (!$done) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $done) { } 0 1 1
elsif (not builtin::blessed($done)) { } 0 1 1
537 0 $done = File::Rsync::Mirror::Recentfile::Done->new();
538 0 $done->_rfinterval ($self->interval);
539 0 $self->_done ( $done );
540 } elsif (!blessed $done) {
541 # when the serializer does not support blessed objects
542 0 bless $done, 'File::Rsync::Mirror::Recentfile::Done';
543 0 $self->_done ( $done );
544 }
545 1 return $done;
546 }
547  
548 =head2 $tempfilename = $obj->get_remote_recentfile_as_tempfile ()
549  
550 Stores the remote I<recentfile> locally as a tempfile. The caller is
551 responsible to remove the file after use.
552  
553 Note: if you're intending to act as an rsync server for other slaves,
554 then you must prefer this method to fetch that file with
555 get_remotefile(). Otherwise downstream mirrors would expect you to
556 already have mirrored all the files that are in the I<recentfile>
557 before you have them mirrored.
558  
559 =cut
560  
561 1 ▶sub get_remote_recentfile_as_tempfile {
Subroutine get_remote_recentfile_as_tempfile: called CC=14 SCAR=43.1
Pod documented
562 1 my($self) = @_;
563 1 mkpath $self->localroot;
564 1 my $fh;
565 my $trfilename;
566 1 ▶ if ( $self->_use_tempfile() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_tempfile) { } 0 1 1
567 0 ▶ if ($self->ttl_reached) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->ttl_reached) { } 0 0 0
568 0 $fh = $self->_current_tempfile_fh;
569 0 $trfilename = $self->rfilename;
570 } else {
571 0 return $self->_current_tempfile;
572 }
573 } else {
574 1 $trfilename = $self->rfilename;
575 }
576  
577 1 my $dst;
578 1 ▶ if ($fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 0 1 1
579 0 $dst = $self->_current_tempfile;
580 } else {
581 1 $fh = $self->_get_remote_rat_provide_tempfile_object ($trfilename);
582 1 $dst = $fh->filename;
583 1 $self->_current_tempfile ($dst);
584 1 my $rfile = eval { $self->rfile; }; # may fail (RECENT.recent has no rfile)
585 1 ▶ if (defined $rfile && -e $rfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rfile and -e $rfile) 0 1 1
Condition33%1/3
defined $rfile and -e $rfile
!ll&&!rl&&r
010
MC/DC0%0/2
defined $rfile and -e $rfile
defined $rfile -e $rfile
Truth table33%1/3
A and B
A= defined $rfileB= -e $rfile
ABresult
0X0
100
111
586 # saving on bandwidth. Might need to be configurable
587 # $self->bandwidth_is_cheap?
588 0 ▶ cp $rfile, $dst or die "Could not copy '$rfile' to '$dst': $!"
Branch: 1 branch
BranchTrueFalseTotal
cp($rfile, $dst) or die "Could not copy '${rfile}' to '${dst}': $!" 0 0 0
589 }
590 }
591 1 my $src = join ("/",
592 $self->remoteroot,
593 $trfilename,
594 );
595 1 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 1 1
596 0 ▶ my $doing = -e $dst ? "Sync" : "Get";
Branch: 1 branch
BranchTrueFalseTotal
-e $dst ? : 0 0 0
597 0 my $display_dst = join "/", "...", basename(dirname($dst)), basename($dst);
598 0 my $LFH = $self->_logfilehandle;
599 0 printf $LFH
600 (
601 "%-4s %d (1/1/%s) temp %s ... ",
602 $doing,
603 time,
604 $self->interval,
605 $display_dst,
606 );
607 }
608 1 my $gaveup = 0;
609 1 my $retried = 0;
610 1 local($ENV{LANG}) = "C";
611 1 ▶ while (!$self->rsync->exec(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->rsync->exec("src", $src, "dst", $dst)) 0 0 0
612 src => $src,
613 dst => $dst,
614 )) {
615 0 $self->register_rsync_error ($self->rsync->err);
616 0 ▶ if (++$retried >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$retried >= 3) 0 0 0
617 0 warn "XXX giving up";
618 0 $gaveup = 1;
619 0 last;
620 }
621 }
622 0 ▶ if ($gaveup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gaveup) { } 0 0 0
623 0 my $LFH = $self->_logfilehandle;
624 0 printf $LFH "Warning: gave up mirroring %s, will try again later", $self->interval;
625 } else {
626 0 $self->_refresh_internals ($dst);
627 0 $self->have_mirrored (Time::HiRes::time);
628 0 $self->un_register_rsync_error ();
629 }
630 0 $self->unseed;
631 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
632 0 my $LFH = $self->_logfilehandle;
633 0 print $LFH "DONE\n";
634 }
635 0 my $mode = 0644;
636 0 ▶ chmod $mode, $dst or die "Could not chmod $mode '$dst': $!";
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode, $dst or die "Could not chmod $mode '${dst}': $!" 0 0 0
637 0 return $dst;
638 }
639  
640 1 ▶sub _verified_tempdir {
Subroutine _verified_tempdir: called CC=4 SCAR=14.6
641 1 my($self) = @_;
642 1 my $tempdir = $self->__verified_tempdir();
643 1 ▶ return $tempdir if defined $tempdir;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tempdir 0 1 1
644 1 ▶ unless ($tempdir = $self->tempdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tempdir = $self->tempdir) 1 0 1
645 1 $tempdir = $self->localroot;
646 }
647 1 ▶ unless (-d $tempdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $tempdir) 0 1 1
648 0 mkpath $tempdir;
649 }
650 1 $self->__verified_tempdir($tempdir);
651 1 return $tempdir;
652 }
653  
654 1 ▶sub _get_remote_rat_provide_tempfile_object {
Subroutine _get_remote_rat_provide_tempfile_object: called CC=3 SCAR=11.3
655 1 my($self, $trfilename) = @_;
656 1 my $_verified_tempdir = $self->_verified_tempdir;
657 1 my $fh = File::Temp->new
658 (TEMPLATE => sprintf(".FRMRecent-%s-XXXX",
659 $trfilename,
660 ),
661 DIR => $_verified_tempdir,
662 SUFFIX => $self->serializer_suffix,
663 UNLINK => $self->_use_tempfile,
664 );
665 1 my $mode = 0644;
666 1 my $dst = $fh->filename;
667 1 ▶ chmod $mode, $dst or die "Could not chmod $mode '$dst': $!";
Branch: 1 branch
BranchTrueFalseTotal
chmod $mode, $dst or die "Could not chmod $mode '${dst}': $!" 1 0 1
668 1 ▶ if ($self->_use_tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_tempfile) 0 1 1
669 0 $self->_current_tempfile_fh ($fh); # delay self destruction
670 }
671 1 return $fh;
672 }
673  
674 0 ▶sub _logfilehandle {
Subroutine _logfilehandle: not called CC=3 SCAR=24.8
675 0 my($self) = @_;
676 0 my $fh;
677 0 ▶ if (my $vl = $self->verboselog) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $vl = $self->verboselog) { } 0 0 0
678 0 ▶ open $fh, ">>", $vl or die "Could not open >> '$vl': $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">>", $vl or die "Could not open >> '${vl}': $!" 0 0 0
679 } else {
680 0 $fh = \*STDERR;
681 }
682 0 return $fh;
683 }
684  
685 =head2 $localpath = $obj->get_remotefile ( $relative_path )
686  
687 Rsyncs one single remote file to local filesystem.
688  
689 Note: no locking is done on this file. Any number of processes may
690 mirror this object.
691  
692 Note II: do not use for recentfiles. If you are a cascading
693 slave/server combination, it would confuse other slaves. They would
694 expect the contents of these recentfiles to be available. Use
695 get_remote_recentfile_as_tempfile() instead.
696  
697 =cut
698  
699 0 ▶sub get_remotefile {
Subroutine get_remotefile: not called CC=6 SCAR=37.4
Pod documented
700 0 my($self, $path) = @_;
701 0 my $dst = File::Spec->catfile($self->localroot, $path);
702 0 mkpath dirname $dst;
703 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
704 0 ▶ my $doing = -e $dst ? "Sync" : "Get";
Branch: 1 branch
BranchTrueFalseTotal
-e $dst ? : 0 0 0
705 0 my $LFH = $self->_logfilehandle;
706 0 printf $LFH
707 (
708 "%-4s %d (1/1/%s) %s ... ",
709 $doing,
710 time,
711 $self->interval,
712 $path,
713 );
714 }
715 0 local($ENV{LANG}) = "C";
716 0 ▶ my $remoteroot = $self->remoteroot or die "Alert: missing remoteroot. Cannot continue";
Branch: 1 branch
BranchTrueFalseTotal
my $remoteroot = $self->remoteroot or die "Alert: missing remoteroot. Cannot continue" 0 0 0
717 0 ▶ while (!$self->rsync->exec(
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->rsync->exec("src", join("/", $remoteroot, $path), "dst", $dst)) 0 0 0
718 src => join("/",
719 $remoteroot,
720 $path),
721 dst => $dst,
722 )) {
723 0 $self->register_rsync_error ($self->rsync->err);
724 }
725 0 $self->un_register_rsync_error ();
726 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
727 0 my $LFH = $self->_logfilehandle;
728 0 print $LFH "DONE\n";
729 }
730 0 return $dst;
731 }
732  
733 =head2 $obj->interval ( $interval_spec )
734  
735 Get/set accessor. $interval_spec is a string and described below in
736 the section INTERVAL SPEC.
737  
738 =cut
739  
740 13950 ▶sub interval {
Subroutine interval: called CC=3 SCAR=11.0
Pod documented
741 13950 my ($self, $interval) = @_;
742 13950 ▶ if (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) 990 12960 13950
743 990 $self->_interval($interval);
744 990 $self->_rfile(undef);
745 }
746 13950 $interval = $self->_interval;
747 13950 ▶ unless (defined $interval) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $interval) 1 13949 13950
748 # do not ask the $self too much, it recurses!
749 1 require Carp;
750 1 Carp::confess("Alert: interval undefined for '".$self."'. Cannot continue.");
751 }
752 13949 return $interval;
753 }
754  
755 =head2 $secs = $obj->interval_secs ( $interval_spec )
756  
757 $interval_spec is described below in the section INTERVAL SPEC. If
758 empty defaults to the inherent interval for this object.
759  
760 =cut
761  
762 5148 ▶sub interval_secs {
Subroutine interval_secs: called CC=7 SCAR=21.3
Pod documented
763 5148 my ($self, $interval) = @_;
764 5148 ▶ $interval ||= $self->interval;
Condition66%2/3
$interval ||= $self->interval
l!l&&r!l&&!r
226928790
MC/DC0%0/2
$interval ||= $self->interval
$interval $self->interval
Truth table66%2/3
A ||= B
A= $intervalB= $self->interval
ABresult
1X1
011
000
765 5147 ▶ unless (defined $interval) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $interval) 0 5147 5147
766 0 die "interval_secs() called without argument on an object without a declared one";
767 }
768 5147 ▶ my ($n,$t) = $interval =~ /^(\d*)([smhdWMQYZ]$)/ or
Branch: 1 branch
BranchTrueFalseTotal
() = $interval =~ /^(\d*)([smhdWMQYZ]$)/ or die "Could not determine seconds from interval[$interval]" 5146 1 5147
769 die "Could not determine seconds from interval[$interval]";
770 5146 ▶ if ($interval eq "Z") {
Branch: 2 branches
BranchTrueFalseTotal
if ($interval eq 'Z') { } 187 4959 5146
elsif (exists $seconds{$t} and $n =~ /^\d+$/) { } 4959 0 4959
771 187 return MAX_INT;
772 ▶ } elsif (exists $seconds{$t} and $n =~ /^\d+$/) {
Condition33%1/3
exists $seconds{$t} and $n =~ /^\d+$/
!ll&&!rl&&r
004959
MC/DC0%0/2
exists $seconds{$t} and $n =~ /^\d+$/
exists $seconds{$t} $n =~ /^\d+$/
Truth table33%1/3
A and B
A= exists $seconds{$t}B= $n =~ /^\d+$/
ABresult
0X0
100
111
773 4959 return $seconds{$t}*$n;
774 } else {
775 0 die "Invalid interval specification: n[$n]t[$t]";
776 }
777 }
778  
779 =head2 $obj->localroot ( $localroot )
780  
781 Get/set accessor. The local root of the tree. Guaranteed without
782 trailing slash.
783  
784 =cut
785  
786 1972 ▶sub localroot {
Subroutine localroot: called CC=2 SCAR=6.9
Pod documented
787 1972 my ($self, $localroot) = @_;
788 1972 ▶ if (@_ >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ >= 2) 320 1652 1972
789 320 $localroot =~ s|/$||;
790 320 $self->_localroot($localroot);
791 320 $self->_rfile(undef);
792 }
793 1972 $localroot = $self->_localroot;
794 }
795  
796 =head2 $ret = $obj->local_path($path_found_in_recentfile)
797  
798 Combines the path to our local mirror and the path of an object found
799 in this I<recentfile>. In other words: the target of a mirror operation.
800  
801 Implementation note: We split on slashes and then use
802 File::Spec::catfile to adjust to the local operating system.
803  
804 =cut
805  
806 0 ▶sub local_path {
Subroutine local_path: not called CC=2 SCAR=17.9
Pod documented
807 0 my($self,$path) = @_;
808 0 ▶ unless (defined $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $path) 0 0 0
809 # seems like a degenerated case
810 0 return $self->localroot;
811 }
812 0 my @p = split m|/|, $path;
813 0 File::Spec->catfile($self->localroot,@p);
814 }
815  
816 =head2 (void) $obj->lock
817  
818 Locking is implemented with an C<mkdir> on a locking directory
819 (C<.lock> appended to $rfile).
820  
821 =cut
822  
823 612 ▶sub lock {
Subroutine lock: called CC=14 SCAR=42.3
Pod documented
824 612 my ($self) = @_;
825 # not using flock because it locks on filehandles instead of
826 # old school ressources.
827 612 ▶ my $locked = $self->_is_locked and return;
Branch: 1 branch
BranchTrueFalseTotal
my $locked = $self->_is_locked and return 0 612 612
828 612 my $rfile = $self->rfile;
829 # XXX need a way to allow breaking the lock
830 612 my $start = time;
831 612 ▶ my $locktimeout = $self->locktimeout || 600;
Condition50%1/2
$self->locktimeout || 600
l!l
0612
MC/DC0%0/1
$self->locktimeout || 600
$self->locktimeout
Truth table50%1/2
A
A= $self->locktimeout
Aresult
11
00
832 612 my %have_warned;
833 612 my $lockdir = "$rfile.lock";
834 612 my $procfile = "$lockdir/process";
835 612 ▶ GETLOCK: while (not mkdir $lockdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (mkdir $lockdir) 0 612 612
836 0 ▶ if (open my $fh, "<", $procfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '<', $procfile) { } 0 0 0
837 0 chomp(my $process = <$fh>);
838 0 ▶ if (0) {
Branch: 3 branches
BranchTrueFalseTotal
if (do { not $process =~ /^\d+$/ }) { } 0 0 0
elsif ($$ == $process) { } 0 0 0
elsif (kill 0, $process) { } 0 0 0
839 } elsif ($process !~ /^\d+$/) {
840 0 ▶ warn "Warning: unknown process holds a lock in '$lockdir', waiting..." unless $have_warned{unknown}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $have_warned{"unknown"}++ 0 0 0
841 } elsif ($$ == $process) {
842 0 last GETLOCK;
843 } elsif (kill 0, $process) {
844 0 ▶ warn "Warning: process $process holds a lock in '$lockdir', waiting..." unless $have_warned{$process}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $have_warned{$process}++ 0 0 0
845 } else {
846 0 warn "Warning: breaking lock held by process $process";
847 0 sleep 1;
848 0 last GETLOCK;
849 }
850 } else {
851 0 ▶ warn "Warning: unknown process holds a lock in '$lockdir', waiting..." unless $have_warned{unknown}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $have_warned{"unknown"}++ 0 0 0
852 }
853 0 Time::HiRes::sleep 0.01;
854 0 ▶ if (time - $start > $locktimeout) {
Branch: 1 branch
BranchTrueFalseTotal
if (time - $start > $locktimeout) 0 0 0
855 0 die "Could not acquire lockdirectory '$rfile.lock': $!";
856 }
857 } # GETLOCK
858 612 ▶ open my $fh, ">", $procfile or die "Could not open >$procfile\: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $procfile or die "Could not open >${procfile}: $!" 612 0 612
859 612 print $fh $$, "\n";
860 612 ▶ close $fh or die "Could not close: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Could not close: $!" 612 0 612
861 612 $self->_is_locked (1);
862 }
863  
864 =head2 (void) $obj->merge ($other)
865  
866 Bulk update of this object with another one. It's used to merge a
867 smaller and younger $other object into the current one. If this file
868 is a C<Z> file, then we normally do not merge in objects of type
869 C<delete>; this can be overridden by setting
870 keep_delete_objects_forever. But if we encounter an object of type
871 delete we delete the corresponding C<new> object if we have it.
872  
873 If there is nothing to be merged, nothing is done.
874  
875 =cut
876  
877 141 ▶sub merge {
Subroutine merge: called CC=2 SCAR=7.0
Pod documented
878 141 my($self, $other) = @_;
879 141 $self->_merge_sanitycheck ( $other );
880 141 $other->lock;
881 141 ▶ my $other_recent = $other->recent_events || [];
Condition50%1/2
$other->recent_events || []
l!l
1410
MC/DC0%0/1
$other->recent_events || []
$other->recent_events
Truth table50%1/2
A
A= $other->recent_events
Aresult
11
00
882 141 $self->lock;
883 141 $self->_merge_locked ( $other, $other_recent );
884 141 $self->unlock;
885 141 $other->unlock;
886 }
887  
888 141 ▶sub _merge_locked {
Subroutine _merge_locked: called CC=25 SCAR=33.1
889 141 my($self, $other, $other_recent) = @_;
890 141 ▶ my $my_recent = $self->recent_events || [];
Condition50%1/2
$self->recent_events || []
l!l
1410
MC/DC0%0/1
$self->recent_events || []
$self->recent_events
Truth table50%1/2
A
A= $self->recent_events
Aresult
11
00
891  
892 # calculate the target time span
893 141 ▶ my $myepoch = $my_recent->[0] ? $my_recent->[0]{epoch} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$my_recent->[0] ? : 126 15 141
894 141 ▶ my $epoch = $other_recent->[0] ? $other_recent->[0]{epoch} : $myepoch;
Branch: 1 branch
BranchTrueFalseTotal
$other_recent->[0] ? : 141 0 141
895 141 my $oldest_allowed = 0;
896 141 my $something_done;
897 141 ▶ unless ($my_recent->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($my_recent->[0]) 15 126 141
898 # obstetrics
899 15 $something_done = 1;
900 }
901 141 ▶ if ($epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($epoch) 141 0 141
902 141 ▶ if (($other->dirtymark||0) ne ($self->dirtymark||0)) {
Branch: 2 branches
BranchTrueFalseTotal
if (($other->dirtymark || 0) ne ($self->dirtymark || 0)) { } 45 96 141
elsif (my $merged = $self->merged) { } 88 8 96
Condition75%3/4
$other->dirtymark || 0
l!l
1410
$self->dirtymark || 0
l!l
12615
MC/DC0%0/1
$other->dirtymark || 0
$other->dirtymark
MC/DC100%1/1
$self->dirtymark || 0
$self->dirtymark
Truth table50%1/2
A
A= $other->dirtymark
Aresult
11
00
Truth table100%2/2
A
A= $self->dirtymark
Aresult
11
00
903 45 $oldest_allowed = 0;
904 45 $something_done = 1;
905 } elsif (my $merged = $self->merged) {
906 88 my $secs = $self->interval_secs();
907 88 ▶ $oldest_allowed = min($epoch - $secs, $merged->{epoch}||0);
Condition50%1/2
$merged->{'epoch'} || 0
l!l
880
MC/DC0%0/1
$merged->{'epoch'} || 0
$merged->{'epoch'}
Truth table50%1/2
A
A= $merged->{'epoch'}
Aresult
11
00
908 88 ▶ if (@$other_recent and
Branch: 1 branch
BranchTrueFalseTotal
if (@$other_recent and &_bigfloatlt($other_recent->[-1]{"epoch"}, $oldest_allowed)) 0 88 88
Condition33%1/3
@$other_recent and &_bigfloatlt($other_recent->[-1]{"epoch"}, $oldest_allowed)
!ll&&!rl&&r
0880
MC/DC0%0/2
@$other_recent and &_bigfloatlt($other_recent->[-1]{"epoch"}, $oldest_allowed)
@$other_recent &_bigfloatlt($other_recent->[-1]{"epoch"}, $oldest_allowed)
Truth table33%1/3
A and B
A= @$other_recentB= &_bigfloatlt($other_recent->[-1]{"epoch"}, $oldest_allowed)
ABresult
0X0
100
111
909 _bigfloatlt($other_recent->[-1]{epoch}, $oldest_allowed)
910 ) {
911 0 $oldest_allowed = $other_recent->[-1]{epoch};
912 }
913 }
914 141 ▶ while (@$my_recent && _bigfloatlt($my_recent->[-1]{epoch}, $oldest_allowed)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$my_recent and &_bigfloatlt($my_recent->[-1]{"epoch"}, $oldest_allowed)) 196 141 337
Condition100%3/3
@$my_recent and &_bigfloatlt($my_recent->[-1]{"epoch"}, $oldest_allowed)
!ll&&!rl&&r
15126196
MC/DC100%2/2
@$my_recent and &_bigfloatlt($my_recent->[-1]{"epoch"}, $oldest_allowed)
@$my_recent &_bigfloatlt($my_recent->[-1]{"epoch"}, $oldest_allowed)
Truth table100%3/3
A and B
A= @$my_recentB= &_bigfloatlt($my_recent->[-1]{"epoch"}, $oldest_allowed)
ABresult
0X0
100
111
915 196 pop @$my_recent;
916 196 $something_done = 1;
917 }
918 }
919  
920 141 my %have_path;
921 141 my $other_recent_filtered = [];
922 141 for my $oev (@$other_recent) {
923 4498 ▶ my $oevepoch = $oev->{epoch} || 0;
Condition50%1/2
$oev->{'epoch'} || 0
l!l
44980
MC/DC0%0/1
$oev->{'epoch'} || 0
$oev->{'epoch'}
Truth table50%1/2
A
A= $oev->{'epoch'}
Aresult
11
00
924 4498 ▶ next if _bigfloatlt($oevepoch, $oldest_allowed);
Branch: 1 branch
BranchTrueFalseTotal
if &_bigfloatlt($oevepoch, $oldest_allowed) 0 4498 4498
925 4498 my $path = $oev->{path};
926 4498 ▶ next if $have_path{$path}++;
Branch: 1 branch
BranchTrueFalseTotal
if $have_path{$path}++ 0 4498 4498
927 4498 ▶ if ( $self->interval eq "Z"
Branch: 1 branch
BranchTrueFalseTotal
if ($self->interval eq 'Z' and $oev->{'type'} eq 'delete' and not $self->keep_delete_objects_forever) { } 3 4495 4498
Condition83%5/6
$self->interval eq "Z" and $oev->{"type"} eq "delete" and not $self->keep_delete_objects_forever
!ll&&!rl&&r
449503
$self->interval eq "Z" and $oev->{"type"} eq "delete"
!ll&&!rl&&r
40514443
MC/DC66%2/3
$self->interval eq "Z" and $oev->{"type"} eq "delete" and not $self->keep_delete_objects_forever
$self->interval eq "Z" $oev->{"type"} eq "delete" not $self->keep_delete_objects_forever
Truth table75%3/4
A and B and not(C)
A= $self->interval eq "Z"B= $oev->{"type"} eq "delete"C= not $self->keep_delete_objects_forever
ABCresult
0XX0
10X0
1100
1111
928 and $oev->{type} eq "delete"
929 and ! $self->keep_delete_objects_forever
930 ) {
931 # do nothing
932 } else {
933 4495 ▶ if (!$myepoch || _bigfloatgt($oevepoch, $myepoch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $myepoch or &_bigfloatgt($oevepoch, $myepoch)) 843 3652 4495
Condition100%3/3
not $myepoch or &_bigfloatgt($oevepoch, $myepoch)
l!l&&r!l&&!r
6971463652
MC/DC100%2/2
not $myepoch or &_bigfloatgt($oevepoch, $myepoch)
not $myepoch &_bigfloatgt($oevepoch, $myepoch)
Truth table100%3/3
not(A) or B
A= not $myepochB= &_bigfloatgt($oevepoch, $myepoch)
ABresult
1X1
011
000
934 843 $something_done = 1;
935 }
936 4495 push @$other_recent_filtered, { epoch => $oev->{epoch}, path => $path, type => $oev->{type} };
937 }
938 }
939 141 ▶ if ($something_done) {
Branch: 1 branch
BranchTrueFalseTotal
if ($something_done) 133 8 141
940 133 $self->_merge_something_done ($other_recent_filtered, $my_recent, $other_recent, $other, \%have_path, $epoch);
941 }
942 }
943  
944 133 ▶sub _merge_something_done {
Subroutine _merge_something_done: called CC=15 SCAR=27.1
945 133 my($self, $other_recent_filtered, $my_recent, $other_recent, $other, $have_path, $epoch) = @_;
946 133 my $recent = [];
947 133 my $epoch_conflict = 0;
948 133 my $last_epoch;
949 133 ▶ ZIP: while (@$other_recent_filtered || @$my_recent) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$other_recent_filtered or @$my_recent) 10332 133 10465
Condition100%3/3
@$other_recent_filtered or @$my_recent
l!l&&r!l&&!r
78832449133
MC/DC100%2/2
@$other_recent_filtered or @$my_recent
@$other_recent_filtered @$my_recent
Truth table100%3/3
A or B
A= @$other_recent_filteredB= @$my_recent
ABresult
1X1
011
000
950 10332 my $event;
951 10332 ▶ if (!@$my_recent ||
Branch: 1 branch
BranchTrueFalseTotal
if (not @$my_recent or @$other_recent_filtered and &_bigfloatge($other_recent_filtered->[0]{'epoch'}, $my_recent->[0]{'epoch'})) { } 4357 5975 10332
Condition100%6/6
not @$my_recent or @$other_recent_filtered and &_bigfloatge($other_recent_filtered->[0]{"epoch"}, $my_recent->[0]{"epoch"})
l!l&&r!l&&!r
72336345975
@$other_recent_filtered and &_bigfloatge($other_recent_filtered->[0]{"epoch"}, $my_recent->[0]{"epoch"})
!ll&&!rl&&r
244935263634
MC/DC100%3/3
not @$my_recent or @$other_recent_filtered and &_bigfloatge($other_recent_filtered->[0]{"epoch"}, $my_recent->[0]{"epoch"})
not @$my_recent @$other_recent_filtered &_bigfloatge($other_recent_filtered->[0]{"epoch"}, $my_recent->[0]{"epoch"})
Truth table100%4/4
not(A) or B and C
A= not @$my_recentB= @$other_recent_filteredC= &_bigfloatge($other_recent_filtered->[0]{"epoch"}, $my_recent->[0]{"epoch"})
ABCresult
1XX1
0111
00X0
0100
952 @$other_recent_filtered && _bigfloatge($other_recent_filtered->[0]{epoch},$my_recent->[0]{epoch})) {
953 4357 $event = shift @$other_recent_filtered;
954 } else {
955 5975 $event = shift @$my_recent;
956 5975 ▶ next ZIP if $have_path->{$event->{path}}++;
Branch: 1 branch
BranchTrueFalseTotal
if $$have_path{$event->{"path"}}++ 3498 2477 5975
957 }
958 6834 ▶ $epoch_conflict=1 if defined $last_epoch && $event->{epoch} eq $last_epoch;
Branch: 1 branch
BranchTrueFalseTotal
if defined $last_epoch and $event->{"epoch"} eq $last_epoch 2 6832 6834
Condition100%3/3
defined $last_epoch and $event->{"epoch"} eq $last_epoch
!ll&&!rl&&r
13366992
MC/DC100%2/2
defined $last_epoch and $event->{"epoch"} eq $last_epoch
defined $last_epoch $event->{"epoch"} eq $last_epoch
Truth table100%3/3
A and B
A= defined $last_epochB= $event->{"epoch"} eq $last_epoch
ABresult
0X0
100
111
959 6834 $last_epoch = $event->{epoch};
960 6834 push @$recent, $event;
961 }
962 133 ▶ if ($epoch_conflict) {
Branch: 1 branch
BranchTrueFalseTotal
if ($epoch_conflict) 2 131 133
963 2 my %have_epoch;
964 2 ▶ for (my $i = $#$recent;$i>=0;$i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 54 2 56
965 54 my $epoch = $recent->[$i]{epoch};
966 54 ▶ if ($have_epoch{$epoch}++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_epoch{$epoch}++) 2 52 54
967 2 ▶ while ($have_epoch{$epoch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($have_epoch{$epoch}) 2 2 4
968 2 $epoch = _increase_a_bit($epoch);
969 }
970 2 $recent->[$i]{epoch} = $epoch;
971 2 $have_epoch{$epoch}++;
972 }
973 }
974 }
975 133 ▶ if (!$self->dirtymark || $other->dirtymark ne $self->dirtymark) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->dirtymark or $other->dirtymark ne $self->dirtymark) 45 88 133
Condition100%3/3
not $self->dirtymark or $other->dirtymark ne $self->dirtymark
l!l&&r!l&&!r
153088
MC/DC100%2/2
not $self->dirtymark or $other->dirtymark ne $self->dirtymark
not $self->dirtymark $other->dirtymark ne $self->dirtymark
Truth table100%3/3
not(A) or B
A= not $self->dirtymarkB= $other->dirtymark ne $self->dirtymark
ABresult
1X1
011
000
976 45 $self->dirtymark ( $other->dirtymark );
977 }
978 133 $self->write_recent($recent);
979 $other->merged({
980 time => Time::HiRes::time, # not used anywhere
981 epoch => $recent->[0]{epoch},
982 133 into_interval => $self->interval, # not used anywhere
983 });
984 133 $other->write_recent($other_recent);
985 }
986  
987 141 ▶sub _merge_sanitycheck {
Subroutine _merge_sanitycheck: called CC=2 SCAR=9.2
988 141 my($self, $other) = @_;
989 141 ▶ if ($self->interval_secs <= $other->interval_secs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->interval_secs <= $other->interval_secs) 0 141 141
990 0 require Carp;
991 0 Carp::confess
992 (sprintf
993 (
994 "Alert: illegal merge operation of a bigger interval[%d] into a smaller[%d]",
995 $self->interval_secs,
996 $other->interval_secs,
997 ));
998 }
999 }
1000  
1001 =head2 merged
1002  
1003 Hashref denoting when this recentfile has been merged into some other
1004 at which epoch.
1005  
1006 =cut
1007  
1008 2866 ▶sub merged {
Subroutine merged: called CC=7 SCAR=20.3
Pod documented
1009 2866 my($self, $set) = @_;
1010 2866 ▶ if (defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 893 1973 2866
1011 893 $self->_merged ($set);
1012 }
1013 2866 my $merged = $self->_merged;
1014 2866 my $into;
1015 2866 ▶ if ($merged and $into = $merged->{into_interval} and defined $self->_interval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merged and $into = $merged->{"into_interval"} and defined $self->_interval) 1854 1012 2866
Condition100%6/6
$merged and $into = $merged->{"into_interval"} and defined $self->_interval
!ll&&!rl&&r
9121001854
$merged and $into = $merged->{"into_interval"}
!ll&&!rl&&r
876361954
MC/DC100%3/3
$merged and $into = $merged->{"into_interval"} and defined $self->_interval
$merged $into = $merged->{"into_interval"} defined $self->_interval
Truth table100%4/4
A and B and C
A= $mergedB= $into = $merged->{"into_interval"}C= defined $self->_interval
ABCresult
0XX0
10X0
1100
1111
1016 # sanity checks
1017 1854 ▶ if ($into eq $self->interval) {
Branch: 2 branches
BranchTrueFalseTotal
if ($into eq $self->interval) { } 0 1854 1854
elsif ($self->interval_secs($into) < $self->interval_secs) { } 0 1854 1854
1018 0 require Carp;
1019 0 Carp::cluck(sprintf
1020 (
1021 "Warning: into_interval[%s] same as own interval[%s]. Danger ahead.",
1022 $into,
1023 $self->interval,
1024 ));
1025 } elsif ($self->interval_secs($into) < $self->interval_secs) {
1026 0 require Carp;
1027 0 Carp::cluck(sprintf
1028 (
1029 "Warning: into_interval_secs[%s] smaller than own interval_secs[%s] on interval[%s]. Danger ahead.",
1030 $self->interval_secs($into),
1031 $self->interval_secs,
1032 $self->interval,
1033 ));
1034 }
1035 }
1036 2866 $merged;
1037 }
1038  
1039 =head2 $hashref = $obj->meta_data
1040  
1041 Returns the hashref of metadata that the server has to add to the
1042 I<recentfile>.
1043  
1044 =cut
1045  
1046 542 ▶sub meta_data {
Subroutine meta_data: called CC=5 SCAR=16.2
Pod documented
1047 542 my($self) = @_;
1048 542 my $ret = $self->{meta};
1049 542 for my $m (
1050 "aggregator",
1051 "canonize",
1052 "comment",
1053 "dirtymark",
1054 "filenameroot",
1055 "interval",
1056 "merged",
1057 "minmax",
1058 "protocol",
1059 "serializer_suffix",
1060 ) {
1061 5420 my $v = $self->$m;
1062 5420 ▶ if (defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 4664 756 5420
1063 4664 $ret->{$m} = $v;
1064 }
1065 }
1066 # XXX need to reset the Producer if I am a writer, keep it when I
1067 # am a reader
1068 $ret->{Producers} ||= {
1069 542 ▶ __PACKAGE__, "$VERSION", # stringified it looks better
Condition50%1/2
$ret->{"Producers"} ||= {__PACKAGE__, "$File::Rsync::Mirror::Recentfile::VERSION", "\$0", $0, "time", &Time::HiRes::time()}
l!l
0542
MC/DC0%0/1
$ret->{"Producers"} ||= {__PACKAGE__, "$File::Rsync::Mirror::Recentfile::VERSION", "\$0", $0, "time", &Time::HiRes::time()}
$ret->{"Producers"}
Truth table50%1/2
A
A= $ret->{"Producers"}
Aresult
11
00
1070 '$0', $0,
1071 'time', Time::HiRes::time,
1072 };
1073 542 ▶ $ret->{dirtymark} ||= Time::HiRes::time;
Condition66%2/3
$ret->{"dirtymark"} ||= &Time::HiRes::time()
l!l&&r!l&&!r
53390
MC/DC0%0/2
$ret->{"dirtymark"} ||= &Time::HiRes::time()
$ret->{"dirtymark"} &Time::HiRes::time()
Truth table66%2/3
A ||= B
A= $ret->{"dirtymark"}B= &Time::HiRes::time()
ABresult
1X1
011
000
1074 542 return $ret;
1075 }
1076  
1077 =head2 $success = $obj->mirror ( %options )
1078  
1079 Mirrors the files in this I<recentfile> as reported by
1080 C<recent_events>. Options named C<after>, C<before>, C<max> are passed
1081 through to the C<recent_events> call. The boolean option C<piecemeal>,
1082 if true, causes C<mirror> to only rsync C<max_files_per_connection>
1083 and keep track of the rsynced files so that future calls will rsync
1084 different files until all files are brought to sync.
1085  
1086 =cut
1087  
1088 1 ▶sub mirror {
Subroutine mirror: called CC=11 SCAR=47.8
Pod documented
1089 1 my($self, %options) = @_;
1090 1 my $trecentfile = $self->get_remote_recentfile_as_tempfile();
1091 0 $self->_use_tempfile (1);
1092 # skip-deletes is inadequat for passthrough within mirror. We
1093 # would never reach uptodateness when a delete were on a
1094 # borderline
1095 0 my %passthrough = map { ($_ => $options{$_}) } qw(before after max);
1096 0 my ($recent_events) = $self->recent_events(%passthrough);
1097 0 my(@error, @dlcollector); # download-collector: array containing paths we need
1098 0 my $first_item = 0;
1099 0 my $last_item = $#$recent_events;
1100 0 my $done = $self->done;
1101 0 my $pathdb = $self->_pathdb;
1102 0 ITEM: for my $i ($first_item..$last_item) {
1103 0 my $status = +{};
1104 0 $self->_mirror_item
1105 (
1106 $i,
1107 $recent_events,
1108 $last_item,
1109 $done,
1110 $pathdb,
1111 \@dlcollector,
1112 \%options,
1113 $status,
1114 \@error,
1115 );
1116 0 ▶ last if $i == $last_item;
Branch: 1 branch
BranchTrueFalseTotal
if $i == $last_item 0 0 0
1117 0 ▶ if ($status->{mustreturn}){
Branch: 1 branch
BranchTrueFalseTotal
if ($status->{"mustreturn"}) 0 0 0
1118 0 ▶ if ($self->_current_tempfile && ! $self->_current_tempfile_fh) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_current_tempfile and not $self->_current_tempfile_fh) 0 0 0
Condition0%0/3
$self->_current_tempfile and not $self->_current_tempfile_fh
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_current_tempfile and not $self->_current_tempfile_fh
$self->_current_tempfile not $self->_current_tempfile_fh
Truth table0%0/3
A and not(B)
A= $self->_current_tempfileB= not $self->_current_tempfile_fh
ABresult
0X0
100
111
1119 # looks like a bug somewhere else
1120 0 my $t = $self->_current_tempfile;
1121 0 ▶ unlink $t or die "Could not unlink '$t': $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink $t or die "Could not unlink '${t}': $!" 0 0 0
1122 0 $self->_current_tempfile(undef);
1123 0 $self->_use_tempfile(0);
1124 }
1125 0 return;
1126 }
1127 }
1128 0 ▶ if (@dlcollector) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dlcollector) 0 0 0
1129 0 my $success = eval { $self->_mirror_dlcollector (\@dlcollector,$pathdb,$recent_events);};
1130 0 ▶ if (!$success || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $success or $@) 0 0 0
Condition0%0/3
not $success or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not $success or $@
not $success $@
Truth table0%0/3
not(A) or B
A= not $successB= $@
ABresult
1X1
011
000
1131 0 warn "Warning: Unknown error while mirroring: $@";
1132 0 push @error, $@;
1133 0 sleep 1;
1134 }
1135 }
1136 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1137 0 my $LFH = $self->_logfilehandle;
1138 0 print $LFH "DONE\n";
1139 }
1140 # once we've gone to the end we consider ourselves free of obligations
1141 0 $self->unseed;
1142 0 $self->_mirror_unhide_tempfile ($trecentfile);
1143 0 $self->_mirror_perform_delayed_ops(\%options);
1144 0 return !@error;
1145 }
1146  
1147 0 ▶sub _mirror_item {
Subroutine _mirror_item: not called CC=13 SCAR=52.0
1148 0 my($self,
1149 $i,
1150 $recent_events,
1151 $last_item,
1152 $done,
1153 $pathdb,
1154 $dlcollector,
1155 $options,
1156 $status,
1157 $error,
1158 ) = @_;
1159 0 my $recent_event = $recent_events->[$i];
1160 0 ▶ return if $done->covered ( $recent_event->{epoch} );
Branch: 1 branch
BranchTrueFalseTotal
if $done->covered($recent_event->{"epoch"}) 0 0 0
1161 0 ▶ if ($pathdb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pathdb) 0 0 0
1162 0 my $rec = $pathdb->{$recent_event->{path}};
1163 0 ▶ if ($rec && $rec->{recentepoch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rec and $rec->{"recentepoch"}) 0 0 0
Condition0%0/3
$rec and $rec->{"recentepoch"}
!ll&&!rl&&r
000
MC/DC0%0/2
$rec and $rec->{"recentepoch"}
$rec $rec->{"recentepoch"}
Truth table0%0/3
A and B
A= $recB= $rec->{"recentepoch"}
ABresult
0X0
100
111
1164 0 ▶ if (_bigfloatgt
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatgt($rec->{"recentepoch"}, $recent_event->{"epoch"})) 0 0 0
1165 ( $rec->{recentepoch}, $recent_event->{epoch} )){
1166 0 $done->register ($recent_events, [$i]);
1167 0 return;
1168 }
1169 }
1170 }
1171 0 my $dst = $self->local_path($recent_event->{path});
1172 0 ▶ if ($recent_event->{type} eq "new"){
Branch: 2 branches
BranchTrueFalseTotal
if ($recent_event->{'type'} eq 'new') { } 0 0 0
elsif ($recent_event->{'type'} eq 'delete') { } 0 0 0
1173 0 $self->_mirror_item_new
1174 (
1175 $dst,
1176 $i,
1177 $last_item,
1178 $recent_events,
1179 $recent_event,
1180 $dlcollector,
1181 $pathdb,
1182 $status,
1183 $error,
1184 $options,
1185 );
1186 } elsif ($recent_event->{type} eq "delete") {
1187 0 my $activity;
1188 0 ▶ if ($options->{'skip-deletes'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{'skip-deletes'}) { } 0 0 0
1189 0 $activity = "skipped";
1190 } else {
1191 0 my @lstat = lstat $dst;
1192 0 ▶ if (! -e _) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -e _) { } 0 0 0
elsif (-l _ or not -d _) { } 0 0 0
1193 0 $activity = "not_found";
1194 ▶ } elsif (-l _ or not -d _) {
Condition0%0/3
-l _ or not -d _
l!l&&r!l&&!r
000
MC/DC0%0/2
-l _ or not -d _
-l _ not -d _
Truth table0%0/3
A or not(B)
A= -l _B= not -d _
ABresult
1X1
011
000
1195 0 $self->delayed_operations->{unlink}{$dst}++;
1196 0 $activity = "deleted";
1197 } else {
1198 0 $self->delayed_operations->{rmdir}{$dst}++;
1199 0 $activity = "deleted";
1200 }
1201 }
1202 0 $done->register ($recent_events, [$i]);
1203 0 ▶ if ($pathdb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pathdb) 0 0 0
1204 0 $self->_mirror_register_path($pathdb,[$recent_event],$activity);
1205 }
1206 } else {
1207 0 warn "Warning: invalid upload type '$recent_event->{type}'";
1208 }
1209 }
1210  
1211 0 ▶sub _mirror_item_new {
Subroutine _mirror_item_new: not called CC=11 SCAR=48.8
1212 0 my($self,
1213 $dst,
1214 $i,
1215 $last_item,
1216 $recent_events,
1217 $recent_event,
1218 $dlcollector,
1219 $pathdb,
1220 $status,
1221 $error,
1222 $options,
1223 ) = @_;
1224 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1225 0 ▶ my $doing = -e $dst ? "Sync" : "Get";
Branch: 1 branch
BranchTrueFalseTotal
-e $dst ? : 0 0 0
1226 0 my $LFH = $self->_logfilehandle;
1227 printf $LFH
1228 (
1229 "%-4s %d (%d/%d/%s) %s ... ",
1230 $doing,
1231 time,
1232 1+$i,
1233 1+$last_item,
1234 $self->interval,
1235 $recent_event->{path},
1236 0 );
1237 }
1238 0 ▶ my $max_files_per_connection = $self->max_files_per_connection || 42;
Condition0%0/2
$self->max_files_per_connection || 42
l!l
00
MC/DC0%0/1
$self->max_files_per_connection || 42
$self->max_files_per_connection
Truth table0%0/2
A
A= $self->max_files_per_connection
Aresult
11
00
1239 0 my $success;
1240 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1241 0 my $LFH = $self->_logfilehandle;
1242 0 print $LFH "\n";
1243 }
1244 0 push @$dlcollector, { rev => $recent_event, i => $i };
1245 0 ▶ if (@$dlcollector >= $max_files_per_connection) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$dlcollector >= $max_files_per_connection) { } 0 0 0
1246 0 $success = eval {$self->_mirror_dlcollector ($dlcollector,$pathdb,$recent_events);};
1247 0 my $sleep = $self->sleep_per_connection;
1248 0 ▶ $sleep = 0.42 unless defined $sleep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sleep 0 0 0
1249 0 Time::HiRes::sleep $sleep;
1250 0 ▶ if ($options->{piecemeal}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"piecemeal"}) 0 0 0
1251 0 $status->{mustreturn} = 1;
1252 0 return;
1253 }
1254 } else {
1255 0 return;
1256 }
1257 0 ▶ if (!$success || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $success or $@) 0 0 0
Condition0%0/3
not $success or $@
l!l&&r!l&&!r
000
MC/DC0%0/2
not $success or $@
not $success $@
Truth table0%0/3
not(A) or B
A= not $successB= $@
ABresult
1X1
011
000
1258 0 warn "Warning: Error while mirroring: $@";
1259 0 push @$error, $@;
1260 0 sleep 1;
1261 }
1262 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1263 0 my $LFH = $self->_logfilehandle;
1264 0 print $LFH "DONE\n";
1265 }
1266 }
1267  
1268 0 ▶sub _mirror_dlcollector {
Subroutine _mirror_dlcollector: not called CC=2 SCAR=17.9
1269 0 my($self,$xcoll,$pathdb,$recent_events) = @_;
1270 0 my $success = $self->mirror_path([map {$_->{rev}{path}} @$xcoll]);
1271 0 ▶ if ($pathdb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pathdb) 0 0 0
1272 0 $self->_mirror_register_path($pathdb,[map {$_->{rev}} @$xcoll],"rsync");
1273 }
1274 0 $self->done->register($recent_events, [map {$_->{i}} @$xcoll]);
1275 0 @$xcoll = ();
1276 0 return $success;
1277 }
1278  
1279 0 ▶sub _mirror_register_path {
Subroutine _mirror_register_path: not called CC=2 SCAR=17.9
1280 0 my($self,$pathdb,$coll,$activity) = @_;
1281 0 my $time = time;
1282 0 for my $item (@$coll) {
1283 $pathdb->{$item->{path}} =
1284 {
1285 recentepoch => $item->{epoch},
1286 0 ($activity."_on") => $time,
1287 };
1288 }
1289 }
1290  
1291 0 ▶sub _mirror_unhide_tempfile {
Subroutine _mirror_unhide_tempfile: not called CC=3 SCAR=24.8
1292 0 my($self, $trecentfile) = @_;
1293 0 my $rfile = $self->rfile;
1294 0 ▶ if (rename $trecentfile, $rfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (rename $trecentfile, $rfile) { } 0 0 0
1295 # warn "DEBUG: renamed '$trecentfile' to '$rfile'";
1296 } else {
1297 0 require Carp;
1298 0 Carp::confess("Could not rename '$trecentfile' to '$rfile': $!");
1299 }
1300 0 $self->_use_tempfile (0);
1301 0 ▶ if (my $ctfh = $self->_current_tempfile_fh) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctfh = $self->_current_tempfile_fh) 0 0 0
1302 0 $ctfh->unlink_on_destroy (0);
1303 0 $self->_current_tempfile_fh (undef);
1304 }
1305 }
1306  
1307 0 ▶sub _mirror_perform_delayed_ops {
Subroutine _mirror_perform_delayed_ops: not called CC=9 SCAR=45.0
1308 0 my($self,$options) = @_;
1309 0 my $delayed = $self->delayed_operations;
1310 0 for my $dst (keys %{$delayed->{unlink}}) {
1311 0 ▶ unless (unlink $dst) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $dst) 0 0 0
1312 0 require Carp;
1313 0 ▶ Carp::cluck ( "Warning: Error while unlinking '$dst': $!" ) if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} 0 0 0
1314 }
1315 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1316 0 my $doing = "Del";
1317 0 my $LFH = $self->_logfilehandle;
1318 0 printf $LFH
1319 (
1320 "%-4s %d (%s) %s DONE\n",
1321 $doing,
1322 time,
1323 $self->interval,
1324 $dst,
1325 );
1326 0 delete $delayed->{unlink}{$dst};
1327 }
1328 }
1329 0 for my $dst (sort {length($b) <=> length($a)} keys %{$delayed->{rmdir}}) {
1330 0 ▶ unless (rmdir $dst) {
Branch: 1 branch
BranchTrueFalseTotal
unless (rmdir $dst) 0 0 0
1331 0 require Carp;
1332 0 ▶ Carp::cluck ( "Warning: Error on rmdir '$dst': $!" ) if $options->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $options->{"verbose"} 0 0 0
1333 }
1334 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1335 0 my $doing = "Del";
1336 0 my $LFH = $self->_logfilehandle;
1337 0 printf $LFH
1338 (
1339 "%-4s %d (%s) %s DONE\n",
1340 $doing,
1341 time,
1342 $self->interval,
1343 $dst,
1344 );
1345 0 delete $delayed->{rmdir}{$dst};
1346 }
1347 }
1348 }
1349  
1350 =head2 $success = $obj->mirror_path ( $arrref | $path )
1351  
1352 If the argument is a scalar it is treated as a path. The remote path
1353 is mirrored into the local copy. $path is the path found in the
1354 I<recentfile>, i.e. it is relative to the root directory of the
1355 mirror.
1356  
1357 If the argument is an array reference then all elements are treated as
1358 a path below the current tree and all are rsynced with a single
1359 command (and a single connection).
1360  
1361 =cut
1362  
1363 0 ▶sub mirror_path {
Subroutine mirror_path: not called CC=14 SCAR=53.5
Pod documented
1364 0 my($self,$path) = @_;
1365 # XXX simplify the two branches such that $path is treated as
1366 # [$path] maybe even demand the argument as an arrayref to
1367 # simplify docs and code. (rsync-over-recentfile-2.pl uses the
1368 # interface)
1369 0 ▶ if (ref $path and ref $path eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $path and ref $path eq 'ARRAY') { } 0 0 0
Condition0%0/3
ref $path and ref $path eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $path and ref $path eq "ARRAY"
ref $path ref $path eq "ARRAY"
Truth table0%0/3
A and B
A= ref $pathB= ref $path eq "ARRAY"
ABresult
0X0
100
111
1370 0 my $dst = $self->localroot;
1371 0 mkpath dirname $dst;
1372 0 my($fh) = File::Temp->new(TEMPLATE => sprintf(".%s-XXXX",
1373 lc $self->filenameroot,
1374 ),
1375 TMPDIR => 1,
1376 UNLINK => 0,
1377 );
1378 0 for my $p (@$path) {
1379 0 print $fh $p, "\n";
1380 }
1381 0 $fh->flush;
1382 0 $fh->unlink_on_destroy(1);
1383 0 my $gaveup = 0;
1384 0 my $retried = 0;
1385 0 local($ENV{LANG}) = "C";
1386 0 ▶ while (!$self->rsync->exec
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->rsync->exec("src", join("/", $self->remoteroot), "dst", $dst, "files-from", $fh->filename)) 0 0 0
1387 (
1388 src => join("/",
1389 $self->remoteroot,
1390 ),
1391 dst => $dst,
1392 'files-from' => $fh->filename,
1393 )) {
1394 0 my(@err) = $self->rsync->err;
1395 0 ▶ if ($self->_my_ignore_link_stat_errors && "@err" =~ m{^ rsync: \s link_stat }x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x) 0 0 0
Condition0%0/3
$self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x
$self->_my_ignore_link_stat_errors join($", @err) =~ /^ rsync: \s link_stat /x
Truth table0%0/3
A and B
A= $self->_my_ignore_link_stat_errorsB= join($", @err) =~ /^ rsync: \s link_stat /x
ABresult
0X0
100
111
1396 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1397 0 my $LFH = $self->_logfilehandle;
1398 0 print $LFH "Info: ignoring link_stat error '@err'";
1399 }
1400 0 return 1;
1401 }
1402 0 $self->register_rsync_error (@err);
1403 0 ▶ if (++$retried >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$retried >= 3) 0 0 0
1404 0 my $batchsize = @$path;
1405 0 warn "The number of rsync retries now reached 3 within a batch of size $batchsize. Error was '@err'. Giving up now, will retry later, ";
1406 0 $gaveup = 1;
1407 0 last;
1408 }
1409 0 sleep 1;
1410 }
1411 0 ▶ unless ($gaveup) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gaveup) 0 0 0
1412 0 $self->un_register_rsync_error ();
1413 }
1414 } else {
1415 0 my $dst = $self->local_path($path);
1416 0 mkpath dirname $dst;
1417 0 local($ENV{LANG}) = "C";
1418 0 ▶ while (!$self->rsync->exec
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->rsync->exec("src", join("/", $self->remoteroot, $path), "dst", $dst)) 0 0 0
1419 (
1420 src => join("/",
1421 $self->remoteroot,
1422 $path
1423 ),
1424 dst => $dst,
1425 )) {
1426 0 my(@err) = $self->rsync->err;
1427 0 ▶ if ($self->_my_ignore_link_stat_errors && "@err" =~ m{^ rsync: \s link_stat }x ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x) 0 0 0
Condition0%0/3
$self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_my_ignore_link_stat_errors and join($", @err) =~ /^ rsync: \s link_stat /x
$self->_my_ignore_link_stat_errors join($", @err) =~ /^ rsync: \s link_stat /x
Truth table0%0/3
A and B
A= $self->_my_ignore_link_stat_errorsB= join($", @err) =~ /^ rsync: \s link_stat /x
ABresult
0X0
100
111
1428 0 ▶ if ($self->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose) 0 0 0
1429 0 my $LFH = $self->_logfilehandle;
1430 0 print $LFH "Info: ignoring link_stat error '@err'";
1431 }
1432 0 return 1;
1433 }
1434 0 $self->register_rsync_error (@err);
1435 }
1436 0 $self->un_register_rsync_error ();
1437 }
1438 0 return 1;
1439 }
1440  
1441 0 ▶sub _my_ignore_link_stat_errors {
Subroutine _my_ignore_link_stat_errors: not called CC=2 SCAR=17.9
1442 0 my($self) = @_;
1443 0 my $x = $self->ignore_link_stat_errors;
1444 0 ▶ $x = 1 unless defined $x;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $x 0 0 0
1445 0 return $x;
1446 }
1447  
1448 1309 ▶sub _my_current_rfile {
Subroutine _my_current_rfile: called CC=4 SCAR=15.5
1449 1309 my($self) = @_;
1450 1309 my $rfile;
1451 1309 ▶ if ($self->_use_tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_use_tempfile) 0 1309 1309
1452 0 $rfile = $self->_current_tempfile;
1453 }
1454 1309 ▶ unless ($rfile && -s $rfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rfile and -s $rfile) 1309 0 1309
Condition33%1/3
$rfile and -s $rfile
!ll&&!rl&&r
130900
MC/DC0%0/2
$rfile and -s $rfile
$rfile -s $rfile
Truth table33%1/3
A and B
A= $rfileB= -s $rfile
ABresult
0X0
100
111
1455 1309 $rfile = $self->rfile;
1456 }
1457 1309 return $rfile;
1458 }
1459  
1460 =head2 $path = $obj->naive_path_normalize ($path)
1461  
1462 Takes an absolute unix style path as argument and canonicalizes it to
1463 a shorter path if possible, removing things like double slashes or
1464 C</./> and removes references to C<../> directories to get a shorter
1465 unambiguos path. This is used to make the code easier that determines
1466 if a file passed to C<upgrade()> is indeed below our C<localroot>.
1467  
1468 =cut
1469  
1470 259 ▶sub naive_path_normalize {
Subroutine naive_path_normalize: called CC=2 SCAR=7.0
Pod documented
1471 259 my($self,$path) = @_;
1472 259 $path =~ s|/+|/|g;
1473 259 ▶ 1 while $path =~ s|/[^/]+/\.\./|/|;
Branch: 1 branch
BranchTrueFalseTotal
$path =~ s[/[^/]+/\.\./][/] and do { '???' } 0 259 259
1474 259 $path =~ s|/$||;
1475 259 $path;
1476 }
1477  
1478 =head2 $ret = $obj->read_recent_1 ( $data )
1479  
1480 Delegate of C<recent_events()> on protocol 1
1481  
1482 =cut
1483  
1484 1285 ▶sub read_recent_1 {
Subroutine read_recent_1: called CC=1 SCAR=0.0
Pod documented
1485 1285 my($self, $data) = @_;
1486 1285 return $data->{recent};
1487 }
1488  
1489 =head2 $array_ref = $obj->recent_events ( %options )
1490  
1491 Note: the code relies on the resource being written atomically. We
1492 cannot lock because we may have no write access. If the caller has
1493 write access (eg. aggregate() or update()), it has to care for any
1494 necessary locking and it MUST write atomically.
1495  
1496 If C<$options{after}> is specified, only file events after this
1497 timestamp are returned.
1498  
1499 If C<$options{before}> is specified, only file events before this
1500 timestamp are returned.
1501  
1502 If C<$options{max}> is specified only a maximum of this many most
1503 recent events is returned.
1504  
1505 If C<$options{'skip-deletes'}> is specified, no files-to-be-deleted
1506 will be returned.
1507  
1508 If C<$options{contains}> is specified the value must be a hash
1509 reference containing a query. The query may contain the keys C<epoch>,
1510 C<path>, and C<type>. Each represents a condition that must be met. If
1511 there is more than one such key, the conditions are ANDed.
1512  
1513 If C<$options{info}> is specified, it must be a hashref. This hashref
1514 will be filled with metadata about the unfiltered recent_events of
1515 this object, in key C<first> there is the first item, in key C<last>
1516 is the last.
1517  
1518 =cut
1519  
1520 1308 ▶sub recent_events {
Subroutine recent_events: called CC=8 SCAR=22.2
Pod documented
1521 1308 my ($self, %options) = @_;
1522 1308 my $info = $options{info};
1523 1308 ▶ if ($self->is_slave) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_slave) 0 1308 1308
1524 # XXX seems dubious, might produce tempfiles without removing them?
1525 0 $self->get_remote_recentfile_as_tempfile;
1526 }
1527 1308 ▶ my $rfile_or_tempfile = $self->_my_current_rfile or return [];
Branch: 1 branch
BranchTrueFalseTotal
my $rfile_or_tempfile = $self->_my_current_rfile or return [] 1308 0 1308
1528 1308 ▶ -e $rfile_or_tempfile or return [];
Branch: 1 branch
BranchTrueFalseTotal
-e $rfile_or_tempfile or return [] 1285 23 1308
1529 1285 my $suffix = $self->serializer_suffix;
1530 1285 my ($data) = eval {
1531 1285 $self->_try_deserialize
1532 (
1533 $suffix,
1534 $rfile_or_tempfile,
1535 );
1536 };
1537 1285 my $err = $@;
1538 1285 ▶ if ($err or !$data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err or not $data) 0 1285 1285
Condition33%1/3
$err or not $data
l!l&&r!l&&!r
001285
MC/DC0%0/2
$err or not $data
$err not $data
Truth table33%1/3
A or not(B)
A= $errB= not $data
ABresult
1X1
011
000
1539 0 return [];
1540 }
1541 1285 my $re;
1542 1285 ▶ if (reftype $data eq 'ARRAY') { # protocol 0
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::reftype($data) eq 'ARRAY') { } 0 1285 1285
1543 0 $re = $data;
1544 } else {
1545 1285 $re = $self->_recent_events_protocol_x
1546 (
1547 $data,
1548 $rfile_or_tempfile,
1549 );
1550 }
1551 1285 ▶ return $re unless grep {defined $options{$_}} qw(after before contains max skip-deletes);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $options{$_};} "after", "before", "contains", "max", "skip-deletes" 885 400 1285
1552 400 $self->_recent_events_handle_options ($re, \%options);
1553 }
1554  
1555 # File::Rsync::Mirror::Recentfile::_recent_events_handle_options
1556 400 ▶sub _recent_events_handle_options {
Subroutine _recent_events_handle_options: called CC=17 SCAR=40.3
1557 400 my($self, $re, $options) = @_;
1558 400 my $last_item = $#$re;
1559 400 my $info = $options->{info};
1560 400 ▶ if ($info) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info) 400 0 400
1561 400 $info->{first} = $re->[0];
1562 400 $info->{last} = $re->[-1];
1563 }
1564 400 ▶ if (defined $options->{after}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"after"}) 0 400 400
1565 0 ▶ if ($re->[0]{epoch} > $options->{after}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re->[0]{'epoch'} > $options->{'after'}) { } 0 0 0
1566 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = &first(sub { $re->[$_]{"epoch"} <= $options->{"after"}; } , 0 .. $re->$#*)) 0 0 0
1567 my $f = first
1568 0 ▶ {$re->[$_]{epoch} <= $options->{after}}
Subroutine __ANON__: not called CC=1 SCAR=6.9
1569 0..$#$re
1570 ) {
1571 0 $last_item = $f-1;
1572 }
1573 } else {
1574 0 $last_item = -1;
1575 }
1576 }
1577 400 my $first_item = 0;
1578 400 ▶ if (defined $options->{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"before"}) 400 0 400
1579 400 ▶ if ($re->[0]{epoch} > $options->{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re->[0]{'epoch'} > $options->{'before'}) { } 371 29 400
1580 371 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = &first(sub { $re->[$_]{"epoch"} < $options->{"before"}; } , 0 .. $last_item)) 117 254 371
1581 my $f = first
1582 28725 ▶ {$re->[$_]{epoch} < $options->{before}}
Subroutine __ANON__: called CC=1 SCAR=0.0
1583 0..$last_item
1584 ) {
1585 117 $first_item = $f;
1586 }
1587 } else {
1588 29 $first_item = 0;
1589 }
1590 }
1591 400 ▶ if (0 != $first_item || -1 != $last_item) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 != $first_item or -1 != $last_item) 400 0 400
Condition66%2/3
0 != $first_item or -1 != $last_item
l!l&&r!l&&!r
1172830
MC/DC0%0/2
0 != $first_item or -1 != $last_item
0 != $first_item -1 != $last_item
Truth table66%2/3
A or B
A= 0 != $first_itemB= -1 != $last_item
ABresult
1X1
011
000
1592 400 @$re = splice @$re, $first_item, 1+$last_item-$first_item;
1593 }
1594 400 ▶ if ($options->{'skip-deletes'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"skip-deletes"}) 0 400 400
1595 0 @$re = grep { $_->{type} ne "delete" } @$re;
1596 }
1597 400 ▶ if (my $contopt = $options->{contains}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $contopt = $options->{"contains"}) 0 400 400
1598 0 my $seen_allowed = 0;
1599 0 for my $allow (qw(epoch path type)) {
1600 0 ▶ if (exists $contopt->{$allow}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $contopt->{$allow}) 0 0 0
1601 0 $seen_allowed++;
1602 0 my $v = $contopt->{$allow};
1603 0 @$re = grep { $_->{$allow} eq $v } @$re;
1604 }
1605 }
1606 0 ▶ if (keys %$contopt > $seen_allowed) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %$contopt > $seen_allowed) 0 0 0
1607 0 require Carp;
1608 0 Carp::confess
1609 (sprintf "unknown query: %s", join ", ", %$contopt);
1610 }
1611 }
1612 400 ▶ if ($options->{max} && @$re > $options->{max}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options->{"max"} and @$re > $options->{"max"}) 0 400 400
Condition33%1/3
$options->{"max"} and @$re > $options->{"max"}
!ll&&!rl&&r
40000
MC/DC0%0/2
$options->{"max"} and @$re > $options->{"max"}
$options->{"max"} @$re > $options->{"max"}
Truth table33%1/3
A and B
A= $options->{"max"}B= @$re > $options->{"max"}
ABresult
0X0
100
111
1613 0 @$re = splice @$re, 0, $options->{max};
1614 }
1615 400 $re;
1616 }
1617  
1618 1285 ▶sub _recent_events_protocol_x {
Subroutine _recent_events_protocol_x: called CC=6 SCAR=18.1
1619 1285 my($self,
1620 $data,
1621 $rfile_or_tempfile,
1622 ) = @_;
1623 1285 my $meth = sprintf "read_recent_%d", $data->{meta}{protocol};
1624 # we may be reading meta for the first time
1625 1285 ▶ while (my($k,$v) = each %{$data->{meta}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$data{"meta"};}) 12277 1285 13562
1626 12277 ▶ if ($k ne lc $k){ # "Producers"
Branch: 1 branch
BranchTrueFalseTotal
if ($k ne lc $k) 1285 10992 12277
1627 1285 $self->{ORIG}{$k} = $v;
1628 1285 next;
1629 }
1630 10992 ▶ next if defined $self->$k;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->$k 8910 2082 10992
1631 2082 $self->$k($v);
1632 }
1633 1285 my $re = $self->$meth ($data);
1634 1285 my $minmax;
1635 1285 ▶ if (my @stat = stat $rfile_or_tempfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@stat) = stat $rfile_or_tempfile) { } 1285 0 1285
1636 1285 $minmax = { mtime => $stat[9] };
1637 } else {
1638 # defensive because ABH encountered:
1639  
1640 #### Sync 1239828608 (1/1/Z) temp .../authors/.FRMRecent-RECENT-Z.yaml-
1641 #### Ydr_.yaml ... DONE
1642 #### Cannot stat '/mirrors/CPAN/authors/.FRMRecent-RECENT-Z.yaml-
1643 #### Ydr_.yaml': No such file or directory at /usr/lib/perl5/site_perl/
1644 #### 5.8.8/File/Rsync/Mirror/Recentfile.pm line 1558.
1645 #### unlink0: /mirrors/CPAN/authors/.FRMRecent-RECENT-Z.yaml-Ydr_.yaml is
1646 #### gone already at cpan-pause.pl line 0
1647
1648 0 my $LFH = $self->_logfilehandle;
1649 0 print $LFH "Warning (maybe harmless): Cannot stat '$rfile_or_tempfile': $!"
1650 }
1651 1285 ▶ if (@$re) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$re) 1285 0 1285
1652 1285 $minmax->{min} = $re->[-1]{epoch};
1653 1285 $minmax->{max} = $re->[0]{epoch};
1654 }
1655 1285 $self->minmax ( $minmax );
1656 1285 return $re;
1657 }
1658  
1659 1285 ▶sub _try_deserialize {
Subroutine _try_deserialize: called CC=4 SCAR=22.6
1660 1285 my($self,
1661 $suffix,
1662 $rfile_or_tempfile,
1663 ) = @_;
1664 1285 ▶ if ($suffix eq ".yaml") {
Branch: 2 branches
BranchTrueFalseTotal
if ($suffix eq '.yaml') { } 1285 0 1285
elsif ($HAVE->{'Data::Serializer'}) { } 0 0 0
1665 1285 require YAML::Syck;
1666 1285 YAML::Syck::LoadFile($rfile_or_tempfile);
1667 } elsif ($HAVE->{"Data::Serializer"}) {
1668 my $serializer = Data::Serializer->new
1669 0 ( serializer => $serializers{$suffix} );
1670 my $serialized = do
1671 0 {
1672 0 ▶ open my $fh, $rfile_or_tempfile or die "Could not open: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $rfile_or_tempfile or die "Could not open: $!" 0 0 0
1673 0 local $/;
1674 0 <$fh>;
1675 };
1676 0 $serializer->raw_deserialize($serialized);
1677 } else {
1678 0 die "Data::Serializer not installed, cannot proceed with suffix '$suffix'";
1679 }
1680 }
1681  
1682 0 ▶sub _refresh_internals {
Subroutine _refresh_internals: not called CC=5 SCAR=34.0
1683 0 my($self, $dst) = @_;
1684 0 my $class = ref $self;
1685 0 my $rfpeek = $class->new_from_file ($dst);
1686 0 for my $acc (qw(
1687 _merged
1688 minmax
1689 )) {
1690 0 $self->$acc ( $rfpeek->$acc );
1691 }
1692 0 my $old_dirtymark = $self->dirtymark;
1693 0 my $new_dirtymark = $rfpeek->dirtymark;
1694 0 ▶ if ($old_dirtymark && $new_dirtymark && $new_dirtymark ne $old_dirtymark) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_dirtymark and $new_dirtymark and $new_dirtymark ne $old_dirtymark) 0 0 0
Condition0%0/6
$old_dirtymark and $new_dirtymark and $new_dirtymark ne $old_dirtymark
!ll&&!rl&&r
000
$old_dirtymark and $new_dirtymark
!ll&&!rl&&r
000
MC/DC0%0/3
$old_dirtymark and $new_dirtymark and $new_dirtymark ne $old_dirtymark
$old_dirtymark $new_dirtymark $new_dirtymark ne $old_dirtymark
Truth table0%0/4
A and B and C
A= $old_dirtymarkB= $new_dirtymarkC= $new_dirtymark ne $old_dirtymark
ABCresult
0XX0
10X0
1100
1111
1695 0 $self->done->reset;
1696 0 $self->dirtymark ( $new_dirtymark );
1697 0 $self->_uptodateness_ever_reached(0);
1698 0 $self->seed;
1699 }
1700 }
1701  
1702 =head2 $ret = $obj->rfilename
1703  
1704 Just the basename of our I<recentfile>, composed from C<filenameroot>,
1705 a dash, C<interval>, and C<serializer_suffix>. E.g. C<RECENT-6h.yaml>
1706  
1707 =cut
1708  
1709 1327 ▶sub rfilename {
Subroutine rfilename: called CC=1 SCAR=0.0
Pod documented
1710 1327 my($self) = @_;
1711 1327 my $file = sprintf("%s-%s%s",
1712 $self->filenameroot,
1713 $self->interval,
1714 $self->serializer_suffix,
1715 );
1716 1327 return $file;
1717 }
1718  
1719 =head2 $str = $self->remote_dir
1720  
1721 The directory we are mirroring from.
1722  
1723 =cut
1724  
1725 3 ▶sub remote_dir {
Subroutine remote_dir: called CC=2 SCAR=6.9
Pod documented
1726 3 my($self, $set) = @_;
1727 3 ▶ if (defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 1 2 3
1728 1 $self->_remote_dir ($set);
1729 }
1730 3 my $x = $self->_remote_dir;
1731 3 $self->is_slave (1);
1732 3 return $x;
1733 }
1734  
1735 =head2 $str = $obj->remoteroot
1736  
1737 =head2 (void) $obj->remoteroot ( $set )
1738  
1739 Get/Set the composed prefix needed when rsyncing from a remote module.
1740 If remote_host, remote_module, and remote_dir are set, it is composed
1741 from these.
1742  
1743 =cut
1744  
1745 1 ▶sub remoteroot {
Subroutine remoteroot: called CC=6 SCAR=19.9
Pod documented
1746 1 my($self, $set) = @_;
1747 1 ▶ if (defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 0 1 1
1748 0 $self->_remoteroot($set);
1749 }
1750 1 my $remoteroot = $self->_remoteroot;
1751 1 ▶ unless (defined $remoteroot) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $remoteroot) 1 0 1
1752 1 ▶ $remoteroot = sprintf
Branch: 3 branches
BranchTrueFalseTotal
defined $self->remote_host ? : 0 1 1
defined $self->remote_module ? : 0 1 1
defined $self->remote_dir ? : 1 0 1
1753 (
1754 "%s%s%s",
1755 defined $self->remote_host ? ($self->remote_host."::") : "",
1756 defined $self->remote_module ? ($self->remote_module."/") : "",
1757 defined $self->remote_dir ? $self->remote_dir : "",
1758 );
1759 1 $self->_remoteroot($remoteroot);
1760 }
1761 1 return $remoteroot;
1762 }
1763  
1764 =head2 (void) $obj->split_rfilename ( $recentfilename )
1765  
1766 Inverse method to C<rfilename>. C<$recentfilename> is a plain filename
1767 of the pattern
1768  
1769 $filenameroot-$interval$serializer_suffix
1770  
1771 e.g.
1772  
1773 RECENT-1M.yaml
1774  
1775 This filename is split into its parts and the parts are fed to the
1776 object itself.
1777  
1778 =cut
1779  
1780 0 ▶sub split_rfilename {
Subroutine split_rfilename: not called CC=2 SCAR=17.9
Pod documented
1781 0 my($self, $rfname) = @_;
1782 0 my($splitter) = qr(^(.+)-([^-\.]+)(\.[^\.]+));
1783 0 ▶ if (my($f,$i,$s) = $rfname =~ $splitter) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $rfname =~ /$splitter/) { } 0 0 0
1784 0 $self->filenameroot ($f);
1785 0 $self->interval ($i);
1786 0 $self->serializer_suffix ($s);
1787 } else {
1788 0 die "Alert: cannot split '$rfname', doesn't match '$splitter'";
1789 }
1790 0 return;
1791 }
1792  
1793 =head2 my $rfile = $obj->rfile
1794  
1795 Returns the full path of the I<recentfile>
1796  
1797 =cut
1798  
1799 3188 ▶sub rfile {
Subroutine rfile: called CC=2 SCAR=6.9
Pod documented
1800 3188 my($self) = @_;
1801 3188 my $rfile = $self->_rfile;
1802 3188 ▶ return $rfile if defined $rfile;
Branch: 1 branch
BranchTrueFalseTotal
if defined $rfile 2197 991 3188
1803 991 $rfile = File::Spec->catfile
1804 ($self->localroot,
1805 $self->rfilename,
1806 );
1807 991 $self->_rfile ($rfile);
1808 991 return $rfile;
1809 }
1810  
1811 =head2 $rsync_obj = $obj->rsync
1812  
1813 The File::Rsync object that this object uses for communicating with an
1814 upstream server.
1815  
1816 =cut
1817  
1818 1 ▶sub rsync {
Subroutine rsync: called CC=4 SCAR=14.6
Pod documented
1819 1 my($self) = @_;
1820 1 my $rsync = $self->_rsync;
1821 1 ▶ unless (defined $rsync) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rsync) 1 0 1
1822 1 ▶ my $rsync_options = $self->rsync_options || {};
Condition50%1/2
$self->rsync_options || {}
l!l
10
MC/DC0%0/1
$self->rsync_options || {}
$self->rsync_options
Truth table50%1/2
A
A= $self->rsync_options
Aresult
11
00
1823 1 ▶ if ($HAVE->{"File::Rsync"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HAVE->{'File::Rsync'}) { } 1 0 1
1824 1 $rsync = File::Rsync->new($rsync_options);
1825 1 $self->_rsync($rsync);
1826 } else {
1827 0 die "File::Rsync required for rsync operations. Cannot continue";
1828 }
1829 }
1830 1 return $rsync;
1831 }
1832  
1833 =head2 (void) $obj->register_rsync_error(@err)
1834  
1835 =head2 (void) $obj->un_register_rsync_error()
1836  
1837 Register_rsync_error is called whenever the File::Rsync object fails
1838 on an exec (say, connection doesn't succeed). It issues a warning and
1839 sleeps for an increasing amount of time. Un_register_rsync_error
1840 resets the error count. See also accessor C<max_rsync_errors>.
1841  
1842 =cut
1843  
1844 {
1845 14 my $no_success_count = 0;
1846 14 my $no_success_time = 0;
1847 0 ▶ sub register_rsync_error {
Subroutine register_rsync_error: not called CC=5 SCAR=34.0
Pod documented
1848 0 my($self, @err) = @_;
1849 0 chomp @err;
1850 0 $no_success_time = time;
1851 0 $no_success_count++;
1852 0 my $max_rsync_errors = $self->max_rsync_errors;
1853 0 ▶ $max_rsync_errors = MAX_INT unless defined $max_rsync_errors;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max_rsync_errors 0 0 0
1854 0 ▶ if ($max_rsync_errors>=0 && $no_success_count >= $max_rsync_errors) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_rsync_errors >= 0 and $no_success_count >= $max_rsync_errors) 0 0 0
Condition0%0/3
$max_rsync_errors >= 0 and $no_success_count >= $max_rsync_errors
!ll&&!rl&&r
000
MC/DC0%0/2
$max_rsync_errors >= 0 and $no_success_count >= $max_rsync_errors
$max_rsync_errors >= 0 $no_success_count >= $max_rsync_errors
Truth table0%0/3
A and B
A= $max_rsync_errors >= 0B= $no_success_count >= $max_rsync_errors
ABresult
0X0
100
111
1855 0 require Carp;
1856 0 Carp::confess
1857 (
1858 sprintf
1859 (
1860 "Alert: Error while rsyncing (%s): '%s', error count: %d, exiting now,",
1861 $self->interval,
1862 join(" ",@err),
1863 $no_success_count,
1864 ));
1865 }
1866 0 my $sleep = 12 * $no_success_count;
1867 0 ▶ $sleep = 300 if $sleep > 300;
Branch: 1 branch
BranchTrueFalseTotal
if $sleep > 300 0 0 0
1868 0 require Carp;
1869 0 Carp::cluck
1870 (sprintf
1871 (
1872 "Warning: %s, Error while rsyncing (%s): '%s', sleeping %d",
1873 scalar(localtime($no_success_time)),
1874 $self->interval,
1875 join(" ",@err),
1876 $sleep,
1877 ));
1878 0 sleep $sleep
1879 }
1880 0 ▶ sub un_register_rsync_error {
Subroutine un_register_rsync_error: not called CC=1 SCAR=6.9
Pod documented
1881 0 my($self) = @_;
1882 0 $no_success_time = 0;
1883 0 $no_success_count = 0;
1884 }
1885 }
1886  
1887 =head2 $clone = $obj->_sparse_clone
1888  
1889 Clones just as much from itself that it does not hurt. Experimental
1890 method.
1891  
1892 Note: what fits better: sparse or shallow? Other suggestions?
1893  
1894 =cut
1895  
1896 14 ▶sub _sparse_clone {
Subroutine _sparse_clone: called CC=3 SCAR=11.0
1897 634 my($self) = @_;
1898 634 my $new = bless {}, ref $self;
1899 634 for my $m (qw(
1900 _interval
1901 _localroot
1902 _remoteroot
1903 _rfile
1904 _use_tempfile
1905 aggregator
1906 filenameroot
1907 ignore_link_stat_errors
1908 is_slave
1909 max_files_per_connection
1910 protocol
1911 rsync_options
1912 serializer_suffix
1913 sleep_per_connection
1914 tempdir
1915 verbose
1916 )) {
1917 10144 my $o = $self->$m;
1918 10144 ▶ $o = Storable::dclone $o if ref $o;
Branch: 1 branch
BranchTrueFalseTotal
if ref $o 644 9500 10144
1919 10144 $new->$m($o);
1920 }
1921 634 $new;
1922 }
1923  
1924 =head2 $boolean = OBJ->ttl_reached ()
1925  
1926 =cut
1927  
1928 0 ▶sub ttl_reached {
Subroutine ttl_reached: not called CC=4 SCAR=30.0
Pod documented
1929 0 my($self) = @_;
1930 0 ▶ my $have_mirrored = $self->have_mirrored || 0;
Condition0%0/2
$self->have_mirrored || 0
l!l
00
MC/DC0%0/1
$self->have_mirrored || 0
$self->have_mirrored
Truth table0%0/2
A
A= $self->have_mirrored
Aresult
11
00
1931 0 my $now = Time::HiRes::time;
1932 0 my $ttl = $self->ttl;
1933 0 ▶ $ttl = 24.2 unless defined $ttl;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ttl 0 0 0
1934 0 ▶ if ($now > $have_mirrored + $ttl) {
Branch: 1 branch
BranchTrueFalseTotal
if ($now > $have_mirrored + $ttl) 0 0 0
1935 0 return 1;
1936 }
1937 0 return 0;
1938 }
1939  
1940 =head2 (void) $obj->unlock()
1941  
1942 Unlocking is implemented with an C<rmdir> on a locking directory
1943 (C<.lock> appended to $rfile).
1944  
1945 =cut
1946  
1947 1604 ▶sub unlock {
Subroutine unlock: called CC=4 SCAR=14.0
Pod documented
1948 1604 my($self) = @_;
1949 1604 ▶ return unless $self->_is_locked;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_locked 992 612 1604
1950 612 my $rfile = $self->rfile;
1951 612 ▶ unlink "$rfile.lock/process" or warn "Could not unlink lockfile '$rfile.lock/process': $!";
Branch: 1 branch
BranchTrueFalseTotal
unlink "$rfile.lock/process" or warn "Could not unlink lockfile '$rfile.lock/process': $!" 612 0 612
1952 612 ▶ rmdir "$rfile.lock" or warn "Could not rmdir lockdir '$rfile.lock': $!";;
Branch: 1 branch
BranchTrueFalseTotal
rmdir "$rfile.lock" or warn "Could not rmdir lockdir '$rfile.lock': $!" 612 0 612
1953 612 $self->_is_locked (0);
1954 }
1955  
1956 =head2 unseed
1957  
1958 Sets this recentfile in the state of not 'seeded'.
1959  
1960 =cut
1961 0 ▶sub unseed {
Subroutine unseed: not called CC=1 SCAR=6.9
Pod documented
1962 0 my($self) = @_;
1963 0 $self->seeded(0);
1964 }
1965  
1966 =head2 $ret = $obj->update ($path, $type)
1967  
1968 =head2 $ret = $obj->update ($path, "new", $dirty_epoch)
1969  
1970 =head2 $ret = $obj->update ()
1971  
1972 Enter one file into the local I<recentfile>. $path is the (usually
1973 absolute) path. If the path is outside I<our> tree, then it is
1974 ignored.
1975  
1976 C<$type> is one of C<new> or C<delete>.
1977  
1978 Events of type C<new> may set $dirty_epoch. $dirty_epoch is normally
1979 not used and the epoch is calculated by the update() routine itself
1980 based on current time. But if there is the demand to insert a
1981 not-so-current file into the dataset, then the caller sets
1982 $dirty_epoch. This causes the epoch of the registered event to become
1983 $dirty_epoch or -- if the exact value given is already taken -- a tiny
1984 bit more. As compensation the dirtymark of the whole dataset is set to
1985 now or the current epoch, whichever is higher. Note: setting the
1986 dirty_epoch to the future is prohibited as it's very unlikely to be
1987 intended: it definitely might wreak havoc with the index files.
1988  
1989 The new file event is unshifted (or, if dirty_epoch is set, inserted
1990 at the place it belongs to, according to the rule to have a sequence
1991 of strictly decreasing timestamps) to the array of recent_events and
1992 the array is shortened to the length of the timespan allowed. This is
1993 usually the timespan specified by the interval of this recentfile but
1994 as long as this recentfile has not been merged to another one, the
1995 timespan may grow without bounds.
1996  
1997 The third form runs an update without inserting a new file. This may
1998 be desired to truncate a recentfile.
1999  
2000 =cut
2001 323 ▶sub _epoch_monotonically_increasing {
Subroutine _epoch_monotonically_increasing: called CC=3 SCAR=11.0
2002 323 my($self,$epoch,$recent) = @_;
2003 323 ▶ return $epoch unless @$recent; # the first one goes unoffended
Branch: 1 branch
BranchTrueFalseTotal
unless @$recent 7 316 323
2004 316 ▶ if (_bigfloatgt("".$epoch,$recent->[0]{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatgt('' . $epoch, $recent->[0]{'epoch'})) { } 283 33 316
2005 283 return $epoch;
2006 } else {
2007 33 return _increase_a_bit($recent->[0]{epoch});
2008 }
2009 }
2010 329 ▶sub update {
Subroutine update: called CC=8 SCAR=21.3
Pod documented
2011 329 my($self,$path,$type,$dirty_epoch) = @_;
2012 329 ▶ if (defined $path or defined $type or defined $dirty_epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path or defined $type or defined $dirty_epoch) 259 70 329
Condition66%4/6
defined $path or defined $type or defined $dirty_epoch
l!l&&r!l&&!r
259070
defined $path or defined $type
l!l&&r!l&&!r
259070
MC/DC33%1/3
defined $path or defined $type or defined $dirty_epoch
defined $path defined $type defined $dirty_epoch
Truth table50%2/4
A or B or C
A= defined $pathB= defined $typeC= defined $dirty_epoch
ABCresult
1XX1
01X1
0011
0000
2013 259 ▶ die "update called without path argument" unless defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 259 259
2014 259 ▶ die "update called without type argument" unless defined $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 259 259
2015 259 ▶ die "update called with illegal type argument: $type" unless $type =~ /(new|delete)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /(new|delete)/ 0 259 259
2016 }
2017 329 $self->lock;
2018 329 my $ctx = $self->_locked_batch_update([{path=>$path,type=>$type,epoch=>$dirty_epoch}]);
2019 329 ▶ $self->write_recent($ctx->{recent}) if $ctx->{something_done};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"something_done"} 272 57 329
2020 329 $self->_assert_symlink;
2021 329 $self->unlock;
2022 }
2023  
2024 =head2 $obj->batch_update($batch)
2025  
2026 Like update but for many files. $batch is an arrayref containing
2027 hashrefs with the structure
2028  
2029 {
2030 path => $path,
2031 type => $type,
2032 epoch => $epoch,
2033 }
2034  
2035  
2036  
2037 =cut
2038 1 ▶sub batch_update {
Subroutine batch_update: called CC=2 SCAR=7.0
Pod documented
2039 1 my($self,$batch) = @_;
2040 1 $self->lock;
2041 1 my $ctx = $self->_locked_batch_update($batch);
2042 1 ▶ $self->write_recent($ctx->{recent}) if $ctx->{something_done};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"something_done"} 1 0 1
2043 1 $self->_assert_symlink;
2044 1 $self->unlock;
2045 }
2046 330 ▶sub _locked_batch_update {
Subroutine _locked_batch_update: called CC=15 SCAR=30.0
2047 330 my($self,$batch) = @_;
2048 330 my $something_done = 0;
2049 330 my $recent = $self->recent_events;
2050 330 ▶ unless ($recent->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($recent->[0]) 8 322 330
2051 # obstetrics
2052 8 $something_done = 1;
2053 }
2054 330 my %paths_in_recent = map { $_->{path} => undef } @$recent;
2055 330 my $interval = $self->interval;
2056 330 my $canonmeth = $self->canonize;
2057 330 ▶ unless ($canonmeth) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($canonmeth) 79 251 330
2058 79 $canonmeth = "naive_path_normalize";
2059 }
2060 330 my $oldest_allowed = 0;
2061 330 my $setting_new_dirty_mark = 0;
2062 330 my $console;
2063 330 ▶ if ($self->verbose && @$batch > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->verbose and @$batch > 1) 0 330 330
Condition66%2/3
$self->verbose and @$batch > 1
!ll&&!rl&&r
32820
MC/DC0%0/2
$self->verbose and @$batch > 1
$self->verbose @$batch > 1
Truth table66%2/3
A and B
A= $self->verboseB= @$batch > 1
ABresult
0X0
100
111
2064 0 eval {require Time::Progress};
2065 0 ▶ warn "dollarat[$@]" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
2066 0 $| = 1;
2067 0 $console = new Time::Progress;
2068 0 $console->attr( min => 1, max => scalar @$batch );
2069 0 print "\n";
2070 }
2071 330 my $i = 0;
2072 330 my $memo_splicepos;
2073 0 ▶ ITEM: for my $item (sort {($b->{epoch}||0) <=> ($a->{epoch}||0)} @$batch) {
Condition0%0/4
$File::Rsync::Mirror::Recentfile::b->{'epoch'} || 0
l!l
00
$File::Rsync::Mirror::Recentfile::a->{'epoch'} || 0
l!l
00
MC/DC0%0/1
$File::Rsync::Mirror::Recentfile::b->{'epoch'} || 0
$File::Rsync::Mirror::Recentfile::b->{'epoch'}
MC/DC0%0/1
$File::Rsync::Mirror::Recentfile::a->{'epoch'} || 0
$File::Rsync::Mirror::Recentfile::a->{'epoch'}
Truth table0%0/2
A
A= $File::Rsync::Mirror::Recentfile::b->{'epoch'}
Aresult
11
00
Truth table0%0/2
A
A= $File::Rsync::Mirror::Recentfile::a->{'epoch'}
Aresult
11
00
2074 329 $i++;
2075 329 ▶ print $console->report( "\rdone %p elapsed: %L (%l sec), ETA %E (%e sec)", $i ) if $console and not $i % 50;
Branch: 1 branch
BranchTrueFalseTotal
if $console and not $i % 50 0 329 329
Condition33%1/3
$console and not $i % 50
!ll&&!rl&&r
32900
MC/DC0%0/2
$console and not $i % 50
$console not $i % 50
Truth table33%1/3
A and not(B)
A= $consoleB= not $i % 50
ABresult
0X0
100
111
2076 329 my $ctx = $self->_update_batch_item($item,$canonmeth,$recent,$setting_new_dirty_mark,$oldest_allowed,$something_done,\%paths_in_recent,$memo_splicepos);
2077 329 $something_done = $ctx->{something_done};
2078 329 $oldest_allowed = $ctx->{oldest_allowed};
2079 329 $setting_new_dirty_mark = $ctx->{setting_new_dirty_mark};
2080 329 $recent = $ctx->{recent};
2081 329 $memo_splicepos = $ctx->{memo_splicepos};
2082 }
2083 330 ▶ print "\n" if $console;
Branch: 1 branch
BranchTrueFalseTotal
if $console 0 330 330
2084 330 ▶ if ($setting_new_dirty_mark) {
Branch: 1 branch
BranchTrueFalseTotal
if ($setting_new_dirty_mark) 6 324 330
2085 6 $oldest_allowed = 0;
2086 }
2087 330 ▶TRUNCATE: while (@$recent) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$recent) 509 1 510
2088 509 ▶ if (_bigfloatlt($recent->[-1]{epoch}, $oldest_allowed)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatlt($recent->[-1]{'epoch'}, $oldest_allowed)) { } 180 329 509
2089 180 pop @$recent;
2090 180 $something_done = 1;
2091 } else {
2092 329 last TRUNCATE;
2093 }
2094 }
2095 330 return {something_done=>$something_done,recent=>$recent};
2096 }
2097 329 ▶sub _update_batch_item {
Subroutine _update_batch_item: called CC=16 SCAR=28.3
2098 329 my($self,$item,$canonmeth,$recent,$setting_new_dirty_mark,$oldest_allowed,$something_done,$paths_in_recent,$memo_splicepos) = @_;
2099 329 my($path,$type,$dirty_epoch) = @{$item}{qw(path type epoch)};
2100 329 ▶ if (defined $path or defined $type or defined $dirty_epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path or defined $type or defined $dirty_epoch) 259 70 329
Condition66%4/6
defined $path or defined $type or defined $dirty_epoch
l!l&&r!l&&!r
259070
defined $path or defined $type
l!l&&r!l&&!r
259070
MC/DC33%1/3
defined $path or defined $type or defined $dirty_epoch
defined $path defined $type defined $dirty_epoch
Truth table50%2/4
A or B or C
A= defined $pathB= defined $typeC= defined $dirty_epoch
ABCresult
1XX1
01X1
0011
0000
2101 259 $path = $self->$canonmeth($path);
2102 }
2103 # you must calculate the time after having locked, of course
2104 329 my $now = Time::HiRes::time;
2105  
2106 329 my $epoch;
2107 329 ▶ if (defined $dirty_epoch && _bigfloatgt($now,$dirty_epoch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dirty_epoch and &_bigfloatgt($now, $dirty_epoch)) { } 6 323 329
Condition66%2/3
defined $dirty_epoch and &_bigfloatgt($now, $dirty_epoch)
!ll&&!rl&&r
32306
MC/DC50%1/2
defined $dirty_epoch and &_bigfloatgt($now, $dirty_epoch)
defined $dirty_epoch &_bigfloatgt($now, $dirty_epoch)
Truth table66%2/3
A and B
A= defined $dirty_epochB= &_bigfloatgt($now, $dirty_epoch)
ABresult
0X0
100
111
2108 6 $epoch = $dirty_epoch;
2109 } else {
2110 323 $epoch = $self->_epoch_monotonically_increasing($now,$recent);
2111 }
2112 329 ▶ $recent ||= [];
Condition50%1/2
$recent ||= []
l!l
3290
MC/DC0%0/1
$recent ||= []
$recent
Truth table50%1/2
A
A= $recent
Aresult
11
00
2113 329 my $merged = $self->merged;
2114 329 ▶ if ($merged->{epoch} && !$setting_new_dirty_mark) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merged->{'epoch'} and not $setting_new_dirty_mark) { } 174 155 329
Condition66%2/3
$merged->{"epoch"} and not $setting_new_dirty_mark
!ll&&!rl&&r
1550174
MC/DC50%1/2
$merged->{"epoch"} and not $setting_new_dirty_mark
$merged->{"epoch"} not $setting_new_dirty_mark
Truth table66%2/3
A and not(B)
A= $merged->{"epoch"}B= not $setting_new_dirty_mark
ABresult
0X0
100
111
2115 174 my $virtualnow = _bigfloatmax($now,$epoch);
2116 # for the lower bound I think we need no big math, we calc already
2117 174 my $secs = $self->interval_secs();
2118 174 $oldest_allowed = min($virtualnow - $secs, $merged->{epoch}, $epoch);
2119 } else {
2120 # as long as we are not merged at all, no limits!
2121 }
2122 329 my $lrd = $self->localroot;
2123 329 ▶ if (defined $path && $path =~ s|^\Q$lrd\E||) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $path and $path =~ s/^\Q$lrd\E//) 259 70 329
Condition66%2/3
defined $path and $path =~ s/^\Q$lrd\E//
!ll&&!rl&&r
700259
MC/DC50%1/2
defined $path and $path =~ s/^\Q$lrd\E//
defined $path $path =~ s/^\Q$lrd\E//
Truth table66%2/3
A and B
A= defined $pathB= $path =~ s/^\Q$lrd\E//
ABresult
0X0
100
111
2124 259 $path =~ s|^/||;
2125 259 my $splicepos;
2126 # remove the older duplicates of this $path, irrespective of $type:
2127 259 ▶ if (defined $dirty_epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dirty_epoch) { } 6 253 259
2128 6 my $ctx = $self->_update_with_dirty_epoch($path,$recent,$epoch,$paths_in_recent,$memo_splicepos);
2129 6 $recent = $ctx->{recent};
2130 6 $splicepos = $ctx->{splicepos};
2131 6 $epoch = $ctx->{epoch};
2132 6 my $dirtymark = $self->dirtymark;
2133 6 my $new_dm = $now;
2134 6 ▶ if (_bigfloatgt($epoch, $now)) { # just in case we had to increase it
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatgt($epoch, $now)) 0 6 6
2135 0 $new_dm = $epoch;
2136 }
2137 6 $self->dirtymark($new_dm);
2138 6 $setting_new_dirty_mark = 1;
2139 6 ▶ if (not defined $merged->{epoch} or _bigfloatlt($epoch,$merged->{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $merged->{"epoch"} or &_bigfloatlt($epoch, $merged->{"epoch"})) 6 0 6
Condition33%1/3
not defined $merged->{"epoch"} or &_bigfloatlt($epoch, $merged->{"epoch"})
l!l&&r!l&&!r
060
MC/DC0%0/2
not defined $merged->{"epoch"} or &_bigfloatlt($epoch, $merged->{"epoch"})
not defined $merged->{"epoch"} &_bigfloatlt($epoch, $merged->{"epoch"})
Truth table33%1/3
not(A) or B
A= not defined $merged->{"epoch"}B= &_bigfloatlt($epoch, $merged->{"epoch"})
ABresult
1X1
011
000
2140 6 $self->merged(+{});
2141 }
2142 } else {
2143 253 $recent = [ grep { $_->{path} ne $path } @$recent ];
2144 253 $splicepos = 0;
2145 }
2146 259 ▶ if (defined $splicepos) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $splicepos) 259 0 259
2147 259 splice @$recent, $splicepos, 0, { epoch => $epoch, path => $path, type => $type };
2148 259 $paths_in_recent->{$path} = undef;
2149 }
2150 259 $memo_splicepos = $splicepos;
2151 259 $something_done = 1;
2152 }
2153 return
2154 {
2155 329 something_done => $something_done,
2156 oldest_allowed => $oldest_allowed,
2157 setting_new_dirty_mark => $setting_new_dirty_mark,
2158 recent => $recent,
2159 memo_splicepos => $memo_splicepos,
2160 }
2161 }
2162 6 ▶sub _update_with_dirty_epoch {
Subroutine _update_with_dirty_epoch: called CC=15 SCAR=48.4
2163 6 my($self,$path,$recent,$epoch,$paths_in_recent,$memo_splicepos) = @_;
2164 6 my $splicepos;
2165 6 my $new_recent = [];
2166 6 ▶ if (exists $paths_in_recent->{$path}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $paths_in_recent->{$path}) 0 6 6
2167 0 my $cancel = 0;
2168 0 KNOWN_EVENT: for my $i (0..$#$recent) {
2169 0 ▶ if ($recent->[$i]{path} eq $path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recent->[$i]{'path'} eq $path) { } 0 0 0
2170 0 ▶ if ($recent->[$i]{epoch} eq $epoch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recent->[$i]{"epoch"} eq $epoch) 0 0 0
2171 # nothing to do
2172 0 $cancel = 1;
2173 0 last KNOWN_EVENT;
2174 }
2175 } else {
2176 0 push @$new_recent, $recent->[$i];
2177 }
2178 }
2179 0 ▶ @$recent = @$new_recent unless $cancel;
Branch: 1 branch
BranchTrueFalseTotal
unless $cancel 0 0 0
2180 }
2181 6 ▶ if (!exists $recent->[0] or _bigfloatgt($epoch,$recent->[0]{epoch})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $recent->[0] or &_bigfloatgt($epoch, $recent->[0]{'epoch'})) { } 0 6 6
elsif (&_bigfloatlt($epoch, $recent->[-1]{'epoch'})) { } 6 0 6
Condition33%1/3
not exists $recent->[0] or &_bigfloatgt($epoch, $recent->[0]{"epoch"})
l!l&&r!l&&!r
006
MC/DC0%0/2
not exists $recent->[0] or &_bigfloatgt($epoch, $recent->[0]{"epoch"})
not exists $recent->[0] &_bigfloatgt($epoch, $recent->[0]{"epoch"})
Truth table33%1/3
not(A) or B
A= not exists $recent->[0]B= &_bigfloatgt($epoch, $recent->[0]{"epoch"})
ABresult
1X1
011
000
2182 0 $splicepos = 0;
2183 } elsif (_bigfloatlt($epoch,$recent->[-1]{epoch})) {
2184 6 $splicepos = @$recent;
2185 } else {
2186 0 my $startingpoint;
2187 0 ▶ if (_bigfloatgt($memo_splicepos<=$#$recent && $epoch, $recent->[$memo_splicepos]{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatgt(scalar($memo_splicepos <= $recent->$#* && $epoch), $recent->[$memo_splicepos]{'epoch'})) { } 0 0 0
Condition0%0/3
$memo_splicepos <= $recent->$#* && $epoch
!ll&&!rl&&r
000
MC/DC0%0/2
$memo_splicepos <= $recent->$#* && $epoch
$memo_splicepos <= $recent->$#* $epoch
Truth table0%0/3
A && B
A= $memo_splicepos <= $recent->$#*B= $epoch
ABresult
0X0
100
111
2188 0 $startingpoint = 0;
2189 } else {
2190 0 $startingpoint = $memo_splicepos;
2191 }
2192 0 RECENT: for my $i ($startingpoint..$#$recent) {
2193 0 my $ev = $recent->[$i];
2194 0 ▶ if ($epoch eq $recent->[$i]{epoch}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($epoch eq $recent->[$i]{"epoch"}) 0 0 0
2195 0 ▶ $epoch = _increase_a_bit($epoch, $i ? $recent->[$i-1]{epoch} : undef);
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 0 0 0
2196 }
2197 0 ▶ if (_bigfloatgt($epoch,$recent->[$i]{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_bigfloatgt($epoch, $recent->[$i]{"epoch"})) 0 0 0
2198 0 $splicepos = $i;
2199 0 last RECENT;
2200 }
2201 }
2202 }
2203 return {
2204 6 recent => $recent,
2205 splicepos => $splicepos,
2206 epoch => $epoch,
2207 }
2208 }
2209  
2210 =head2 seed
2211  
2212 Sets this recentfile in the state of 'seeded' which means it has to
2213 re-evaluate its uptodateness.
2214  
2215 =cut
2216 0 ▶sub seed {
Subroutine seed: not called CC=1 SCAR=6.9
Pod documented
2217 0 my($self) = @_;
2218 0 $self->seeded(1);
2219 }
2220  
2221 =head2 seeded
2222  
2223 Tells if the recentfile is in the state 'seeded'.
2224  
2225 =cut
2226 0 ▶sub seeded {
Subroutine seeded: not called CC=3 SCAR=24.8
Pod documented
2227 0 my($self, $set) = @_;
2228 0 ▶ if (defined $set) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set) 0 0 0
2229 0 $self->_seeded ($set);
2230 }
2231 0 my $x = $self->_seeded;
2232 0 ▶ unless (defined $x) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $x) 0 0 0
2233 0 $x = 0;
2234 0 $self->_seeded ($x);
2235 }
2236 0 return $x;
2237 }
2238  
2239 =head2 uptodate
2240  
2241 True if this object has mirrored the complete interval covered by the
2242 current recentfile.
2243  
2244 =cut
2245 0 ▶sub uptodate {
Subroutine uptodate: not called CC=12 SCAR=50.5
Pod documented
2246 0 my($self) = @_;
2247 0 my $uptodate;
2248 my $why;
2249 0 ▶ if ($self->_uptodateness_ever_reached and not $self->seeded) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_uptodateness_ever_reached and not $self->seeded) 0 0 0
Condition0%0/3
$self->_uptodateness_ever_reached and not $self->seeded
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_uptodateness_ever_reached and not $self->seeded
$self->_uptodateness_ever_reached not $self->seeded
Truth table0%0/3
A and not(B)
A= $self->_uptodateness_ever_reachedB= not $self->seeded
ABresult
0X0
100
111
2250 0 $why = "saturated";
2251 0 $uptodate = 1;
2252 }
2253 # it's too easy to misconfigure ttl and related timings and then
2254 # never reach uptodateness, so disabled 2009-03-22
2255 0 if (0 and not defined $uptodate) {
2256 if ($self->ttl_reached){
2257 $why = "ttl_reached returned true, so we are not uptodate";
2258 $uptodate = 0 ;
2259 }
2260 }
2261 0 ▶ unless (defined $uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $uptodate) 0 0 0
2262 # look if recentfile has unchanged timestamp
2263 0 my $minmax = $self->minmax;
2264 0 ▶ if (exists $minmax->{mtime}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $minmax->{"mtime"}) 0 0 0
2265 0 my $rfile = $self->_my_current_rfile;
2266 0 my @stat = stat $rfile;
2267 0 ▶ if (@stat) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stat) { } 0 0 0
2268 0 my $mtime = $stat[9];
2269 0 ▶ if (defined $mtime && defined $minmax->{mtime} && $mtime > $minmax->{mtime}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mtime and defined $minmax->{'mtime'} and $mtime > $minmax->{'mtime'}) { } 0 0 0
Condition0%0/6
defined $mtime and defined $minmax->{"mtime"} and $mtime > $minmax->{"mtime"}
!ll&&!rl&&r
000
defined $mtime and defined $minmax->{"mtime"}
!ll&&!rl&&r
000
MC/DC0%0/3
defined $mtime and defined $minmax->{"mtime"} and $mtime > $minmax->{"mtime"}
defined $mtime defined $minmax->{"mtime"} $mtime > $minmax->{"mtime"}
Truth table0%0/4
A and B and C
A= defined $mtimeB= defined $minmax->{"mtime"}C= $mtime > $minmax->{"mtime"}
ABCresult
0XX0
10X0
1100
1111
2270 0 $why = "mtime[$mtime] of rfile[$rfile] > minmax/mtime[$minmax->{mtime}], so we are not uptodate";
2271 0 $uptodate = 0;
2272 } else {
2273 0 my $covered = $self->done->covered(@$minmax{qw(max min)});
2274 0 ▶ $why = sprintf "minmax covered[%s], so we return that", defined $covered ? $covered : "UNDEF";
Branch: 1 branch
BranchTrueFalseTotal
defined $covered ? : 0 0 0
2275 0 $uptodate = $covered;
2276 }
2277 } else {
2278 0 require Carp;
2279 0 $why = "Could not stat '$rfile': $!";
2280 0 Carp::cluck($why);
2281 0 $uptodate = 0;
2282 }
2283 }
2284 }
2285 0 ▶ unless (defined $uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $uptodate) 0 0 0
2286 0 $why = "fallthrough, so not uptodate";
2287 0 $uptodate = 0;
2288 }
2289 0 ▶ if ($uptodate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uptodate) 0 0 0
2290 0 $self->_uptodateness_ever_reached(1);
2291 }
2292 0 my $remember =
2293 {
2294 uptodate => $uptodate,
2295 why => $why,
2296 };
2297 0 $self->_remember_last_uptodate_call($remember);
2298 0 return $uptodate;
2299 }
2300  
2301 =head2 $obj->write_recent ($recent_files_arrayref)
2302  
2303 Writes a I<recentfile> based on the current reflection of the current
2304 state of the tree limited by the current interval.
2305  
2306 =cut
2307 0 ▶sub _resort {
Subroutine _resort: not called CC=1 SCAR=6.9
2308 0 my($self) = @_;
2309 0 @{$_[1]} = sort { _bigfloatcmp($b->{epoch},$a->{epoch}) } @{$_[1]};
2310 0 return;
2311 }
2312 542 ▶sub write_recent {
Subroutine write_recent: called CC=13 SCAR=26.2
Pod documented
2313 542 my ($self,$recent) = @_;
2314 542 ▶ die "write_recent called without argument" unless defined $recent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $recent 0 542 542
2315 542 my $Last_epoch;
2316 542 SANITYCHECK: for my $i (0..$#$recent) {
2317 20905 ▶ if (defined($Last_epoch) and _bigfloatge($recent->[$i]{epoch},$Last_epoch)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Last_epoch and &_bigfloatge($recent->[$i]{"epoch"}, $Last_epoch)) 0 20905 20905
Condition66%2/3
defined $Last_epoch and &_bigfloatge($recent->[$i]{"epoch"}, $Last_epoch)
!ll&&!rl&&r
541203640
MC/DC0%0/2
defined $Last_epoch and &_bigfloatge($recent->[$i]{"epoch"}, $Last_epoch)
defined $Last_epoch &_bigfloatge($recent->[$i]{"epoch"}, $Last_epoch)
Truth table66%2/3
A and B
A= defined $Last_epochB= &_bigfloatge($recent->[$i]{"epoch"}, $Last_epoch)
ABresult
0X0
100
111
2318 0 require Carp;
2319 Carp::confess(sprintf "Warning: disorder '%s'>='%s', re-sorting %s\n",
2320 0 $recent->[$i]{epoch}, $Last_epoch, $self->interval);
2321 # you may want to:
2322 # $self->_resort($recent);
2323 # last SANITYCHECK;
2324 }
2325 20905 $Last_epoch = $recent->[$i]{epoch};
2326 }
2327 542 my $minmax = $self->minmax;
2328 542 ▶ if (!defined $minmax->{max} || _bigfloatlt($minmax->{max},$recent->[0]{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $minmax->{"max"} or &_bigfloatlt($minmax->{"max"}, $recent->[0]{"epoch"})) 334 208 542
Condition100%3/3
not defined $minmax->{"max"} or &_bigfloatlt($minmax->{"max"}, $recent->[0]{"epoch"})
l!l&&r!l&&!r
22312208
MC/DC100%2/2
not defined $minmax->{"max"} or &_bigfloatlt($minmax->{"max"}, $recent->[0]{"epoch"})
not defined $minmax->{"max"} &_bigfloatlt($minmax->{"max"}, $recent->[0]{"epoch"})
Truth table100%3/3
not(A) or B
A= not defined $minmax->{"max"}B= &_bigfloatlt($minmax->{"max"}, $recent->[0]{"epoch"})
ABresult
1X1
011
000
2329 334 ▶ $minmax->{max} = @$recent && exists $recent->[0]{epoch} ? $recent->[0]{epoch} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$recent && exists $recent->[0]{'epoch'} ? : 333 1 334
Condition66%2/3
@$recent and exists $recent->[0]{"epoch"}
!ll&&!rl&&r
10333
MC/DC50%1/2
@$recent and exists $recent->[0]{"epoch"}
@$recent exists $recent->[0]{"epoch"}
Truth table66%2/3
A and B
A= @$recentB= exists $recent->[0]{"epoch"}
ABresult
0X0
100
111
2330 }
2331 542 ▶ if (!defined $minmax->{min} || _bigfloatlt($minmax->{min},$recent->[-1]{epoch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $minmax->{"min"} or &_bigfloatlt($minmax->{"min"}, $recent->[-1]{"epoch"})) 114 428 542
Condition100%3/3
not defined $minmax->{"min"} or &_bigfloatlt($minmax->{"min"}, $recent->[-1]{"epoch"})
l!l&&r!l&&!r
2292428
MC/DC100%2/2
not defined $minmax->{"min"} or &_bigfloatlt($minmax->{"min"}, $recent->[-1]{"epoch"})
not defined $minmax->{"min"} &_bigfloatlt($minmax->{"min"}, $recent->[-1]{"epoch"})
Truth table100%3/3
not(A) or B
A= not defined $minmax->{"min"}B= &_bigfloatlt($minmax->{"min"}, $recent->[-1]{"epoch"})
ABresult
1X1
011
000
2332 114 ▶ $minmax->{min} = @$recent && exists $recent->[-1]{epoch} ? $recent->[-1]{epoch} : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$recent && exists $recent->[-1]{'epoch'} ? : 113 1 114
Condition66%2/3
@$recent and exists $recent->[-1]{"epoch"}
!ll&&!rl&&r
10113
MC/DC50%1/2
@$recent and exists $recent->[-1]{"epoch"}
@$recent exists $recent->[-1]{"epoch"}
Truth table66%2/3
A and B
A= @$recentB= exists $recent->[-1]{"epoch"}
ABresult
0X0
100
111
2333 }
2334 542 $self->minmax($minmax);
2335 542 my $meth = sprintf "write_%d", $self->protocol;
2336 542 $self->$meth($recent);
2337 }
2338  
2339 =head2 $obj->write_0 ($recent_files_arrayref)
2340  
2341 Delegate of C<write_recent()> on protocol 0
2342  
2343 =cut
2344  
2345 0 ▶sub write_0 {
Subroutine write_0: not called CC=2 SCAR=17.9
Pod documented
2346 0 my ($self,$recent) = @_;
2347 0 my $rfile = $self->rfile;
2348 0 YAML::Syck::DumpFile("$rfile.new",$recent);
2349 0 ▶ rename "$rfile.new", $rfile or die "Could not rename to '$rfile': $!";
Branch: 1 branch
BranchTrueFalseTotal
rename "$rfile.new", $rfile or die "Could not rename to '${rfile}': $!" 0 0 0
2350 }
2351  
2352 =head2 $obj->write_1 ($recent_files_arrayref)
2353  
2354 Delegate of C<write_recent()> on protocol 1
2355  
2356 =cut
2357  
2358 542 ▶sub write_1 {
Subroutine write_1: called CC=6 SCAR=18.4
Pod documented
2359 542 my ($self,$recent) = @_;
2360 542 my $rfile = $self->rfile;
2361 542 my $suffix = $self->serializer_suffix;
2362 542 my $data = {
2363 meta => $self->meta_data,
2364 recent => $recent,
2365 };
2366 542 my $serialized;
2367 542 ▶ if ($suffix eq ".yaml") {
Branch: 2 branches
BranchTrueFalseTotal
if ($suffix eq '.yaml') { } 539 3 542
elsif ($HAVE->{'Data::Serializer'}) { } 3 0 3
2368 539 $serialized = YAML::Syck::Dump($data);
2369 } elsif ($HAVE->{"Data::Serializer"}) {
2370 my $serializer = Data::Serializer->new
2371 3 ( serializer => $serializers{$suffix} );
2372 3 $serialized = $serializer->raw_serialize($data);
2373 } else {
2374 0 die "Data::Serializer not installed, cannot proceed with suffix '$suffix'";
2375 }
2376 542 ▶ open my $fh, ">", "$rfile.new" or die "Could not open >'$rfile.new': $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$rfile.new" or die "Could not open >'$rfile.new': $!" 542 0 542
2377 542 print $fh $serialized;
2378 542 ▶ close $fh or die "Could not close '$rfile.new': $!";
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "Could not close '$rfile.new': $!" 542 0 542
2379 542 ▶ rename "$rfile.new", $rfile or die "Could not rename to '$rfile': $!";
Branch: 1 branch
BranchTrueFalseTotal
rename "$rfile.new", $rfile or die "Could not rename to '${rfile}': $!" 542 0 542
2380 }
2381  
2382 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
2383 14 my $nq = qr/[^"]+/; # non-quotes
2384 14 my @pod_lines =
2385 14 split /\n/, <<'=cut'; %serializers = map { my @x = /"($nq)"\s+=>\s+"($nq)"/; @x } grep {s/^=item\s+C<<\s+(.+)\s+>>$/$1/} @pod_lines; }
2386  
2387 =head1 SERIALIZERS
2388  
2389 The following suffixes are supported and trigger the use of these
2390 serializers:
2391  
2392 =over 4
2393  
2394 =item C<< ".yaml" => "YAML::Syck" >>
2395  
2396 =item C<< ".json" => "JSON" >>
2397  
2398 =item C<< ".sto" => "Storable" >>
2399  
2400 =item C<< ".dd" => "Data::Dumper" >>
2401  
2402 =back
2403  
2404 =cut
2405  
2406 14 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
2407 14 my @pod_lines =
2408 14 split /\n/, <<'=cut'; %seconds = map { eval } grep {s/^=item\s+C<<(.+)>>$/$1/} @pod_lines; }
2409  
2410 =head1 INTERVAL SPEC
2411  
2412 An interval spec is a primitive way to express time spans. Normally it
2413 is composed from an integer and a letter.
2414  
2415 As a special case, a string that consists only of the single letter
2416 C<Z>, stands for MAX_INT seconds.
2417  
2418 The following letters express the specified number of seconds:
2419  
2420 =over 4
2421  
2422 =item C<< s => 1 >>
2423  
2424 =item C<< m => 60 >>
2425  
2426 =item C<< h => 60*60 >>
2427  
2428 =item C<< d => 60*60*24 >>
2429  
2430 =item C<< W => 60*60*24*7 >>
2431  
2432 =item C<< M => 60*60*24*30 >>
2433  
2434 =item C<< Q => 60*60*24*90 >>
2435  
2436 =item C<< Y => 60*60*24*365.25 >>
2437  
2438 =back
2439  
2440 =cut
2441  
2442 =head1 SEE ALSO
2443  
2444 L<File::Rsync::Mirror::Recent>,
2445 L<File::Rsync::Mirror::Recentfile::Done>,
2446 L<File::Rsync::Mirror::Recentfile::FakeBigFloat>
2447  
2448 =head1 BUGS
2449  
2450 Please report any bugs or feature requests through the web interface
2451 at
2452 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=File-Rsync-Mirror-Recentfile>.
2453 I will be notified, and then you'll automatically be notified of
2454 progress on your bug as I make changes.
2455  
2456 =head1 KNOWN BUGS
2457  
2458 Memory hungry: it seems all memory is allocated during the initial
2459 rsync where a list of all files is maintained in memory.
2460  
2461 =head1 SUPPORT
2462  
2463 You can find documentation for this module with the perldoc command.
2464  
2465 perldoc File::Rsync::Mirror::Recentfile
2466  
2467 You can also look for information at:
2468  
2469 =over 4
2470  
2471 =item * RT: CPAN's request tracker
2472  
2473 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=File-Rsync-Mirror-Recentfile>
2474  
2475 =item * AnnoCPAN: Annotated CPAN documentation
2476  
2477 L<http://annocpan.org/dist/File-Rsync-Mirror-Recentfile>
2478  
2479 =item * CPAN Ratings
2480  
2481 L<http://cpanratings.perl.org/d/File-Rsync-Mirror-Recentfile>
2482  
2483 =item * Search CPAN
2484  
2485 L<http://search.cpan.org/dist/File-Rsync-Mirror-Recentfile>
2486  
2487 =back
2488  
2489  
2490 =head1 ACKNOWLEDGEMENTS
2491  
2492 Thanks to RJBS for module-starter.
2493  
2494 =head1 AUTHOR
2495  
2496 Andreas König
2497  
2498 =head1 COPYRIGHT & LICENSE
2499  
2500 Copyright 2008,2009 Andreas König.
2501  
2502 This program is free software; you can redistribute it and/or modify it
2503 under the same terms as Perl itself.
2504  
2505  
2506 =cut
2507  
2508 14 1; # End of File::Rsync::Mirror::Recentfile
2509  
2510 # Local Variables:
2511 # mode: cperl
2512 # cperl-indent-level: 4
2513 # End:
« blib/lib/File/Rsync/Mirror/Recent.pm ↑ Summary bin/rrr-fsck »