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