blib/lib/POE/Component/SmokeBox/Uploads/Rsync.pm

filter: Statementstmt 28.4% 56 / 197 Branchbran 1.4% 1 / 68 Conditioncond 0.0% 0 / 39 MC/DCmcdc 0.0% 0 / 25 Subroutinesub 58.6% 17 / 29 Podpod 66.6% 2 / 3 totaltotal 21.0% 76 / 361 CC 51 SCAR 64.2
CC
51
Cov
19%
spawn
1332.0
_rsync_out_result
30.0
_rsync_status_result
20.0
CRAP 611.6
↑ Summary
1 #
2 # This file is part of POE-Component-SmokeBox-Uploads-Rsync
3 #
4 # This software is copyright (c) 2014 by Apocalypse.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 1 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
10 package POE::Component::SmokeBox::Uploads::Rsync;
11 # git description: release-1.000-7-g9c6e8f2
12 1 $POE::Component::SmokeBox::Uploads::Rsync::VERSION = '1.001';
13 1 our $AUTHORITY = 'cpan:APOCAL';
14  
15 # ABSTRACT: Obtain uploaded CPAN modules via rsync
16  
17 # Import what we need from the POE namespace
18 1 ▶use POE;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use POE::Component::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use parent 'POE::Session::AttributeBased'; # TODO do we really need to prereq 0.09?
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 # The misc stuff we will use
23 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # argh, we need to fool Test::Apocalypse::Dependencies!
26 # Also, this will let dzil autoprereqs pick it up without actually loading it...
27 1 if ( 0 ) {
28 require File::Rsync;
29 }
30  
31 # Set some constants
32 1 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.2
33 1 ▶ if ( ! defined &DEBUG ) { *DEBUG = sub () { 0 } }
Branch: 1 branch
BranchTrueFalseTotal
if (not defined &POE::Component::SmokeBox::Uploads::Rsync::DEBUG) 1 0 1
34 }
35  
36 #<@BinGOs> that works. I have no FRMRecent files anywhere in *this* particular mirror's tree
37 #<@BinGOs> I run rrr-client on the 'velvet' host and rsync to two other boxen from there.
38 #
39 #bash-4.0# cat exclude.cpan
40 #/modules/by-module/*
41 #/modules/by-category/*
42 #*FRMRecent-RECENT*
43 #bash-4.0#
44 #
45 #/usr/pkg/bin/rsync -av --no-owner --delete --exclude-from /root/exclude.cpan --delete-excluded rsync://velvet.bingosnet.co.uk /cpan /home/ftp/CPAN/ 2>&1 | tee -a /root/cpan.log
46  
47 # starts the component!
48 0 ▶sub spawn {
Subroutine spawn: not called CC=36 SCAR=71.9
Pod documented
49 0 my $class = shift;
50 0 $class = $class; # TODO shutup UnusedVars
51  
52 # The options hash
53 0 my %opt;
54  
55 # Support passing in a hash ref or a regular hash
56 0 ▶ if ( scalar @_ == 1 and ref $_[0] and ref( $_[0] ) eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1 and ref $_[0] and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/6
scalar @_ == 1 and ref $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
scalar @_ == 1 and ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/3
scalar @_ == 1 and ref $_[0] and ref $_[0] eq "HASH"
scalar @_ == 1 ref $_[0] ref $_[0] eq "HASH"
Truth table0%0/4
A and B and C
A= scalar @_ == 1B= ref $_[0]C= ref $_[0] eq "HASH"
ABCresult
0XX0
10X0
1100
1111
57 0 %opt = %{ $_[0] };
58 } else {
59 # Sanity checking
60 0 ▶ if ( @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 0 0
61 0 warn __PACKAGE__ . ' requires an even number of options passed to spawn()';
62 0 return 0;
63 }
64  
65 0 %opt = @_;
66 }
67  
68 # lowercase keys
69 0 %opt = map { lc($_) => $opt{$_} } keys %opt;
70  
71 # Should we rsync the entire CPAN or just the authors directory?
72 0 ▶ if ( ! exists $opt{'rsync_all'} or ! defined $opt{'rsync_all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'rsync_all'} && defined $opt{'rsync_all'}) { } 0 0 0
Condition0%0/3
exists $opt{'rsync_all'} && defined $opt{'rsync_all'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'rsync_all'} && defined $opt{'rsync_all'}
exists $opt{'rsync_all'} defined $opt{'rsync_all'}
Truth table0%0/3
A && B
A= exists $opt{'rsync_all'}B= defined $opt{'rsync_all'}
ABresult
0X0
100
111
73 0 if ( DEBUG ) {
74 warn 'Using default RSYNC_ALL = 0';
75 }
76  
77 0 $opt{'rsync_all'} = 0;
78 } else {
79 # booleanize it
80 0 ▶ $opt{'rsync_all'} = $opt{'rsync_all'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opt{'rsync_all'} ? : 0 0 0
81 }
82  
83 # setup the rsync server
84 0 ▶ if ( ! exists $opt{'rsync_src'} or ! defined $opt{'rsync_src'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'rsync_src'} && defined $opt{'rsync_src'}) { } 0 0 0
Condition0%0/3
exists $opt{'rsync_src'} && defined $opt{'rsync_src'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'rsync_src'} && defined $opt{'rsync_src'}
exists $opt{'rsync_src'} defined $opt{'rsync_src'}
Truth table0%0/3
A && B
A= exists $opt{'rsync_src'}B= defined $opt{'rsync_src'}
ABresult
0X0
100
111
85 0 if ( DEBUG ) {
86 warn 'The argument RSYNC_SRC is missing!';
87 }
88 0 return 0;
89 } else {
90 # TODO should we verify it's a valid rsync path?
91 # i.e. 'cpan.cpantesters.org::cpan'
92  
93 # Append the authors/id directory
94 0 ▶ if ( ! $opt{'rsync_all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"rsync_all"}) 0 0 0
95 0 ▶ if ( $opt{'rsync_src'} !~ m|authors/id$| ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"rsync_src"} =~ m[authors/id$]) 0 0 0
96 0 ▶ if ( $opt{'rsync_src'} =~ m|/$| ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{'rsync_src'} =~ m[/$]) { } 0 0 0
97 0 $opt{'rsync_src'} .= 'authors/id';
98 } else {
99 0 $opt{'rsync_src'} .= '/authors/id';
100 }
101 }
102 }
103 }
104  
105 # Setup the rsync local destination
106 # Append the authors directory ( rsync will sync into id automatically )
107 # If we appended "authors/id" then rsync will create a local authors/id/id directory!$!@%#$
108 0 ▶ if ( ! exists $opt{'rsync_dst'} or ! defined $opt{'rsync_dst'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'rsync_dst'} && defined $opt{'rsync_dst'}) { } 0 0 0
Condition0%0/3
exists $opt{'rsync_dst'} && defined $opt{'rsync_dst'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'rsync_dst'} && defined $opt{'rsync_dst'}
exists $opt{'rsync_dst'} defined $opt{'rsync_dst'}
Truth table0%0/3
A && B
A= exists $opt{'rsync_dst'}B= defined $opt{'rsync_dst'}
ABresult
0X0
100
111
109 0 my $dir = File::Spec->catdir( $ENV{HOME}, 'CPAN' );
110 0 ▶ if ( ! $opt{'rsync_all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"rsync_all"}) 0 0 0
111 0 $dir = File::Spec->catdir( $dir, 'authors' );
112 }
113  
114 0 if ( DEBUG ) {
115 warn 'Using default RSYNC_DST = ' . $dir;
116 }
117  
118 # Set the default
119 0 $opt{'rsync_dst'} = $dir;
120 } else {
121 0 ▶ if ( ! $opt{'rsync_all'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"rsync_all"}) 0 0 0
122 0 ▶ if ( $opt{'rsync_dst'} !~ /authors$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt{"rsync_dst"} =~ /authors$/) 0 0 0
123 0 $opt{'rsync_dst'} = File::Spec->catdir( $opt{'rsync_dst'}, 'authors' );
124 }
125 }
126 }
127  
128 # validate the dst path
129 0 ▶ if ( ! -d $opt{'rsync_dst'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $opt{"rsync_dst"}) 0 0 0
130 0 warn "The RSYNC_DST path does not exist ($opt{'rsync_dst'}), please make sure it is a writable directory!";
131 0 return 0;
132 }
133  
134 # setup the RSYNC opts
135 0 ▶ if ( ! exists $opt{'rsync'} or ! defined $opt{'rsync'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'rsync'} && defined $opt{'rsync'}) { } 0 0 0
Condition0%0/3
exists $opt{'rsync'} && defined $opt{'rsync'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'rsync'} && defined $opt{'rsync'}
exists $opt{'rsync'} defined $opt{'rsync'}
Truth table0%0/3
A && B
A= exists $opt{'rsync'}B= defined $opt{'rsync'}
ABresult
0X0
100
111
136 0 if ( DEBUG ) {
137 warn 'Using default RSYNC = { archive=>1, compress=>1, omit-dir-times=>1, itemize-changes=>1, timeout=>600, contimeout=>120, literal=[ --no-motd ] }';
138 }
139  
140 # Set the default
141 0 $opt{'rsync'} = {};
142 } else {
143 0 ▶ if ( ref( $opt{'rsync'} ) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt{"rsync"} ne "HASH") 0 0 0
144 0 warn "The RSYNC argument is not a valid HASH reference!";
145 0 return 0;
146 }
147 }
148  
149 # Cleanup the rsync opts
150 $opt{'rsync'} = {
151 'omit-dir-times' => 1,
152 'archive' => 1,
153 'compress' => 1,
154 'itemize-changes' => 1,
155 'timeout' => 10 * 60, # 10min
156 'contimeout' => 2 * 60, # 2min
157  
158 # skip the motd, which just consumes bandwidth ;)
159 'literal' => [ '--no-motd', ],
160  
161 # if we rsync the entire CPAN, we delete files too!
162 ( $opt{'rsync_all'} ? ( 'delete' => 1 ) : () ),
163  
164 # use the provided options
165 0 ▶ %{ $opt{'rsync'} },
Branch: 1 branch
BranchTrueFalseTotal
$opt{'rsync_all'} ? : 0 0 0
166 ( DEBUG ? ( 'debug' => 1 ) : () ),
167 };
168  
169 # merge rsync_src/dst
170 0 $opt{'rsync'}->{'src'} = delete $opt{'rsync_src'};
171 0 $opt{'rsync'}->{'dst'} = delete $opt{'rsync_dst'};
172  
173 # TODO File::Rsync doesn't support contimeout!
174 # Ticket here: https://rt.cpan.org/Ticket/Display.html?id=67076
175 0 push( @{ $opt{'rsync'}{'literal'} }, "--contimeout=" . delete $opt{'rsync'}{'contimeout'} );
176  
177 # setup the alias
178 0 ▶ if ( ! exists $opt{'alias'} or ! defined $opt{'alias'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opt{"alias"} and defined $opt{"alias"}) 0 0 0
Condition0%0/3
exists $opt{"alias"} and defined $opt{"alias"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{"alias"} and defined $opt{"alias"}
exists $opt{"alias"} defined $opt{"alias"}
Truth table0%0/3
A and B
A= exists $opt{"alias"}B= defined $opt{"alias"}
ABresult
0X0
100
111
179 0 if ( DEBUG ) {
180 warn 'Using default ALIAS = SmokeBox-Rsync';
181 }
182  
183 # Set the default
184 0 $opt{'alias'} = 'SmokeBox-Rsync';
185 }
186  
187 # Setup the interval in seconds
188 0 ▶ if ( ! exists $opt{'interval'} or ! defined $opt{'interval'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'interval'} && defined $opt{'interval'}) { } 0 0 0
Condition0%0/3
exists $opt{'interval'} && defined $opt{'interval'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'interval'} && defined $opt{'interval'}
exists $opt{'interval'} defined $opt{'interval'}
Truth table0%0/3
A && B
A= exists $opt{'interval'}B= defined $opt{'interval'}
ABresult
0X0
100
111
189 0 if ( DEBUG ) {
190 warn 'Using default INTERVAL = 3600';
191 }
192  
193 # set the default
194 0 $opt{'interval'} = 3600;
195 } else {
196 # verify it's a valid numeric amount
197 0 ▶ if ( $opt{'interval'} !~ /^\d+$/ or $opt{'interval'} < 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $opt{"interval"} =~ /^\d+$/ or $opt{"interval"} < 1) 0 0 0
Condition0%0/3
not $opt{"interval"} =~ /^\d+$/ or $opt{"interval"} < 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not $opt{"interval"} =~ /^\d+$/ or $opt{"interval"} < 1
not $opt{"interval"} =~ /^\d+$/ $opt{"interval"} < 1
Truth table0%0/3
not(A) or B
A= not $opt{"interval"} =~ /^\d+$/B= $opt{"interval"} < 1
ABresult
1X1
011
000
198 0 warn "The INTERVAL argument is not a valid number!";
199 0 return 0;
200 }
201 }
202  
203 # Setup the event
204 0 ▶ if ( ! exists $opt{'event'} or ! defined $opt{'event'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opt{"event"} and defined $opt{"event"}) 0 0 0
Condition0%0/3
exists $opt{"event"} and defined $opt{"event"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{"event"} and defined $opt{"event"}
exists $opt{"event"} defined $opt{"event"}
Truth table0%0/3
A and B
A= exists $opt{"event"}B= defined $opt{"event"}
ABresult
0X0
100
111
205 0 if ( DEBUG ) {
206 warn 'Using default EVENT = upload';
207 }
208  
209 # set the default
210 0 $opt{'event'} = 'upload';
211 }
212  
213 # Setup the rsyncdone event
214 0 ▶ if ( ! exists $opt{'rsyncdone'} or ! defined $opt{'rsyncdone'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opt{"rsyncdone"} and defined $opt{"rsyncdone"}) 0 0 0
Condition0%0/3
exists $opt{"rsyncdone"} and defined $opt{"rsyncdone"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{"rsyncdone"} and defined $opt{"rsyncdone"}
exists $opt{"rsyncdone"} defined $opt{"rsyncdone"}
Truth table0%0/3
A and B
A= exists $opt{"rsyncdone"}B= defined $opt{"rsyncdone"}
ABresult
0X0
100
111
215 0 if ( DEBUG ) {
216 warn 'Using default RSYNCDONE = undef';
217 }
218  
219 # set the default
220 0 $opt{'rsyncdone'} = undef;
221 }
222  
223 # Setup the session
224 0 ▶ if ( ! exists $opt{'session'} or ! defined $opt{'session'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opt{'session'} && defined $opt{'session'}) { } 0 0 0
Condition0%0/3
exists $opt{'session'} && defined $opt{'session'}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $opt{'session'} && defined $opt{'session'}
exists $opt{'session'} defined $opt{'session'}
Truth table0%0/3
A && B
A= exists $opt{'session'}B= defined $opt{'session'}
ABresult
0X0
100
111
225 0 if ( DEBUG ) {
226 warn 'Using default SESSION = caller';
227 }
228  
229 # set the default
230 0 $opt{'session'} = undef;
231 } else {
232 # eval it because it might already be a regular scalar...
233 0 eval {
234 # Convert it to an ID
235 0 ▶ if ( $opt{'session'}->isa( 'POE::Session' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt{"session"}->isa("POE::Session")) 0 0 0
236 0 $opt{'session'} = $opt{'session'}->ID;
237 }
238 };
239 }
240  
241 # Create our session
242 POE::Session->create(
243 __PACKAGE__->inline_states(),
244 'heap' => {
245 'ALIAS' => $opt{'alias'},
246 'RSYNC_OPT' => $opt{'rsync'},
247 'RSYNC_ALL' => $opt{'rsync_all'},
248 'INTERVAL' => $opt{'interval'},
249  
250 'SESSION' => $opt{'session'},
251 'EVENT' => $opt{'event'},
252 0 'RSYNCDONE' => $opt{'rsyncdone'},
253 },
254 );
255  
256 # return success
257 0 return 1;
258 }
259  
260 # This starts the component
261 0 ▶sub _start : State {
Subroutine _start: not called CC=3 SCAR=24.8
262 0 if ( DEBUG ) {
263 warn 'Starting alias "' . $_[HEAP]->{'ALIAS'} . '"';
264 }
265  
266 # Set up the alias for ourself
267 0 $_[KERNEL]->alias_set( $_[HEAP]->{'ALIAS'} );
268  
269 # Setup the session
270 0 ▶ if ( ! defined $_[HEAP]->{'SESSION'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $_[3]{"SESSION"}) 0 0 0
271 # Use the sender
272 0 ▶ if ( $_[KERNEL] == $_[SENDER] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[2] == $_[5]) { } 0 0 0
273 0 warn 'Not called from another POE session and SESSION was not set!';
274 0 $_[KERNEL]->yield( 'shutdown' );
275 0 return;
276 } else {
277 0 $_[HEAP]->{'SESSION'} = $_[SENDER]->ID;
278 }
279 }
280  
281 # Give it a refcount
282 0 $_[KERNEL]->refcount_increment( $_[HEAP]->{'SESSION'}, __PACKAGE__ );
283  
284 # Do the first rsync!
285 0 $_[KERNEL]->yield( '_rsync_start' );
286  
287 0 return;
288 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
289  
290 0 ▶sub _rsync_start : State {
Subroutine _rsync_start: not called CC=1 SCAR=6.9
291 0 if ( DEBUG ) {
292 warn 'Starting rsync run...';
293 }
294  
295 0 $_[HEAP]->{'STARTTIME'} = time;
296  
297 # spawn poco-generic
298 $_[HEAP]->{'RSYNC'} = POE::Component::Generic->spawn(
299 'alt_fork' => 1, # conserve memory by using exec
300 'package' => 'File::Rsync',
301 'methods' => [ qw( exec status out err ) ],
302  
303 0 'object_options' => [ %{ $_[HEAP]->{'RSYNC_OPT'} } ],
304 0 'alias' => $_[HEAP]->{'ALIAS'} . '-' . 'Generic',
305  
306 ( DEBUG ? ( 'debug' => 1, 'error' => '_rsync_generic_error' ) : () ),
307 );
308  
309 # tell poco-generic to do it!
310 0 $_[HEAP]->{'RSYNC'}->exec( { 'event' => '_rsync_exec_result' } );
311  
312 0 return;
313 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
314  
315 0 ▶sub _rsync_exec_result : State {
Subroutine _rsync_exec_result: not called CC=2 SCAR=17.9
316 0 my $result = $_[ARG1];
317  
318 0 if ( DEBUG ) {
319 warn "Rsync exec result: $result";
320 }
321  
322 # Was it successful?
323 0 ▶ if ( $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result) { } 0 0 0
324 # Get the stdout listing so we can parse it for uploaded files
325 0 $_[HEAP]->{'RSYNC'}->out( { 'event' => '_rsync_out_result' } );
326 } else {
327 # Get the exit code
328 0 $_[HEAP]->{'RSYNC'}->status( { 'event' => '_rsync_status_result' } );
329 }
330  
331 0 return;
332 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
333  
334 0 ▶sub _rsync_status_result : State {
Subroutine _rsync_status_result: not called CC=4 SCAR=30.0
335 0 my $result = $_[ARG1];
336  
337 # We ignore status 23/24 errors, it happens occassionally...
338 0 ▶ if ( $result == 23 or $result == 24 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result == 23 or $result == 24) { } 0 0 0
Condition0%0/3
$result == 23 or $result == 24
l!l&&r!l&&!r
000
MC/DC0%0/2
$result == 23 or $result == 24
$result == 23 $result == 24
Truth table0%0/3
A or B
A= $result == 23B= $result == 24
ABresult
1X1
011
000
339 0 if ( DEBUG ) {
340 warn "Ignoring Rsync status $result error...";
341 }
342  
343 # Get the stdout listing so we can parse it for uploaded files
344 0 $_[HEAP]->{'RSYNC'}->out( { 'event' => '_rsync_out_result' } );
345 } else {
346 0 if ( DEBUG ) {
347 warn "Rsync exec error - status: $result";
348 $_[HEAP]->{'RSYNC'}->err( { 'event' => '_rsync_err_result' } );
349 } else {
350 # We're done with the rsync subprocess, shut it down!
351 0 $_[KERNEL]->post( $_[HEAP]->{'RSYNC'}->session_id, 'shutdown' );
352 0 undef $_[HEAP]->{'RSYNC'};
353 }
354  
355 # Let the session know the run is done
356 0 ▶ if ( defined $_[HEAP]->{'RSYNCDONE'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[3]{"RSYNCDONE"}) 0 0 0
357 $_[KERNEL]->post( $_[HEAP]->{'SESSION'}, $_[HEAP]->{'RSYNCDONE'}, {
358 'status' => 0,
359 'exit' => $result,
360 'exit_str' => rsync_exit_string( $result ),
361 0 'starttime' => $_[HEAP]->{'STARTTIME'},
362 'stoptime' => time,
363 'dists' => 0,
364 } );
365 }
366  
367 # Do another run in INTERVAL
368 0 $_[KERNEL]->delay_set( '_rsync_start' => $_[HEAP]->{'INTERVAL'} );
369 }
370  
371 0 return;
372 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
373  
374 0 ▶sub _rsync_err_result : State {
Subroutine _rsync_err_result: not called CC=2 SCAR=17.9
375 0 my $result = $_[ARG1];
376  
377 0 warn "Got rsync STDERR:";
378 0 warn $_ for @$result;
379  
380 # We're done with the rsync subprocess, shut it down!
381 0 $_[KERNEL]->post( $_[HEAP]->{'RSYNC'}->session_id, 'shutdown' );
382 0 undef $_[HEAP]->{'RSYNC'};
383  
384 0 return;
385 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
386  
387 0 ▶sub _rsync_out_result : State {
Subroutine _rsync_out_result: not called CC=5 SCAR=34.0
388 0 my $result = $_[ARG1];
389  
390 # We're done with the rsync subprocess, shut it down!
391 0 $_[KERNEL]->post( $_[HEAP]->{'RSYNC'}->session_id, 'shutdown' );
392 0 undef $_[HEAP]->{'RSYNC'};
393  
394 # Parse the result, and inform the session of new uploads!
395 # Look at the rsync man page for details on the itemize-changes format
396 # >f.st...... id/R/RC/RCAPUTO/CHECKSUMS
397 # >f.st...... id/R/RD/RDB/CHECKSUMS
398 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1004.meta
399 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1004.readme
400 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1004.tar.gz
401 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1005.meta
402 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1005.readme
403 # >f+++++++++ id/R/RD/RDB/POE-Component-SNMP-1.1005.tar.gz
404 # >f.st...... id/R/RE/REDICAPS/CHECKSUMS
405 0 my @modules;
406 0 foreach my $l ( @$result ) {
407 # file regex taken from POE::Component::SmokeBox::Uploads::NNTP, thanks BinGOs!
408 # if RSYNC_ALL is enabled, we rsync from the root - otherwise the id directory
409 0 ▶ if ( $l =~ /^\>f\+{9}\s+(?:authors\/)?id\/(\w+\/\w+\/\w+\/.+\.(?:tar\.(?:gz|bz2)|tgz|zip))$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ m[^\>f\+{9}\s+(?:authors/)?id/(\w+/\w+/\w+/.+\.(?:tar\.(?:gz|bz2)|tgz|zip))$]) 0 0 0
410 0 push( @modules, $1 );
411 }
412 }
413  
414 # Let the session know the run is done
415 0 ▶ if ( defined $_[HEAP]->{'RSYNCDONE'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[3]{"RSYNCDONE"}) 0 0 0
416 $_[KERNEL]->post( $_[HEAP]->{'SESSION'}, $_[HEAP]->{'RSYNCDONE'}, {
417 'status' => 1,
418 'exit' => 0,
419 'exit_str' => rsync_exit_string( 0 ),
420 0 'starttime' => $_[HEAP]->{'STARTTIME'},
421 'stoptime' => time,
422 'dists' => scalar @modules,
423 } );
424 }
425  
426 # send off the modules
427 0 foreach my $m ( @modules ) {
428 0 $_[KERNEL]->post( $_[HEAP]->{'SESSION'}, $_[HEAP]->{'EVENT'}, $m );
429 }
430  
431 # Do another run in INTERVAL
432 0 $_[KERNEL]->delay_set( '_rsync_start' => $_[HEAP]->{'INTERVAL'} );
433  
434 0 return;
435 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
436  
437 0 ▶sub _rsync_generic_error : State {
Subroutine _rsync_generic_error: not called CC=2 SCAR=17.9
438 0 my $err = $_[ARG0];
439  
440 0 ▶ if( $err->{stderr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err->{'stderr'}) { } 0 0 0
441 # $err->{stderr} is a line that was printed to the
442 # sub-processes' STDERR. 99% of the time that means from
443 # your code.
444 0 warn "Got stderr: $err->{stderr}";
445 } else {
446 # Wheel error. See L<POE::Wheel::Run/ErrorEvent>
447 # $err->{operation}
448 # $err->{errnum}
449 # $err->{errstr}
450 0 warn "Got wheel error: $err->{operation} ($err->{errnum}): $err->{errstr}";
451 }
452  
453 0 return;
454 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
455  
456 # POE Handlers
457 0 ▶sub _stop : State {
Subroutine _stop: not called CC=1 SCAR=6.9
458 0 if ( DEBUG ) {
459 warn 'Stopping alias "' . $_[HEAP]->{'ALIAS'} . '"';
460 }
461  
462 0 return;
463 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
464  
465 0 ▶sub _child : State {
Subroutine _child: not called CC=1 SCAR=6.9
466 0 return;
467 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
468  
469 0 ▶sub shutdown : State {
Subroutine shutdown: not called CC=3 SCAR=24.8
Pod documented
470 0 if ( DEBUG ) {
471 warn "Shutting down alias '" . $_[HEAP]->{'ALIAS'} . "'";
472 }
473  
474 # cleanup some stuff
475 0 $_[KERNEL]->alias_remove( $_[HEAP]->{'ALIAS'} );
476  
477 # tell poco-generic to shutdown
478 0 ▶ if ( defined $_[HEAP]->{'RSYNC'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[3]{"RSYNC"}) 0 0 0
479 0 $_[KERNEL]->call( $_[HEAP]->{'RSYNC'}->session_id, 'shutdown' );
480 0 undef $_[HEAP]->{'RSYNC'};
481 }
482  
483 # decrement the refcount
484 0 ▶ if ( defined $_[HEAP]->{'SESSION'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[3]{"SESSION"}) 0 0 0
485 0 $_[KERNEL]->refcount_decrement( $_[HEAP]->{'SESSION'}, __PACKAGE__ );
486 }
487  
488 0 return;
489 1 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
490  
491 {
492 # Taken from the rsync v3.0.8 manpage
493 1 my %exitcodes = (
494 0 => 'Success',
495 1 => 'Syntax or usage error',
496 2 => 'Protocol incompatibility',
497 3 => 'Errors selecting input/output files, dirs',
498 4 => 'Requested action not supported: an attempt was made to manipulate 64-bit files on a platform that cannot support them; or an option was specified that is supported by the client and not by the server.',
499 5 => 'Error starting client-server protocol',
500 6 => 'Daemon unable to append to log-file',
501 10 => 'Error in socket I/O',
502 11 => 'Error in file I/O',
503 12 => 'Error in rsync protocol data stream',
504 13 => 'Errors with program diagnostics',
505 14 => 'Error in IPC code',
506 20 => 'Received SIGUSR1 or SIGINT',
507 21 => 'Some error returned by waitpid()',
508 22 => 'Error allocating core memory buffers',
509 23 => 'Partial transfer due to error',
510 24 => 'Partial transfer due to vanished source files',
511 25 => 'The --max-delete limit stopped deletions',
512 30 => 'Timeout in data send/receive',
513 35 => 'Timeout waiting for daemon connection',
514 );
515  
516 0 ▶ sub rsync_exit_string {
Subroutine rsync_exit_string: not called CC=1 SCAR=6.9
Pod undocumented
517 0 return $exitcodes{ $_[0] };
518 }
519 }
520  
521 1 1;
522  
523 __END__
↑ Summary