| 1 | package MMM::Sync::Rsync; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 4 | our @ISA = qw(MMM::Sync); | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | =head1 NAME | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | MMM::Sync::Rsync | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | =cut | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub buildcmd { | ||||||||||||||||||||||||||
|
Subroutine
buildcmd: called CC=12 SCAR=32.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | my @command = ('rsync'); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | if ($self->{options}{rsync_defaults}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | push(@command, split(/ +/, $self->{options}{rsync_defaults})); | |||||||||||||||||||||||||||
| 20 | 1 | } else { push(@command, '-aH'); } | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | if ($self->{options}{rsync_opts}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | push(@command, split(/ +/, $self->{options}{rsync_opts})); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | if ($self->{options}{exclude}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | foreach ( map { split( m/ /, $_ ) } $self->{options}{exclude} ) { | |||||||||||||||||||||||||||
| 28 | 0 | push( @command, '--exclude', $_ ); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | my %mo = ( | |||||||||||||||||||||||||||
| 33 | partialdir => 'partial-dir', | ||||||||||||||||||||||||||||
| 34 | tempdir => 'temp-dir', | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | push(@command, map { | ||||||||||||||||||||||||||||
| 37 | 1 | $self->{options}{$_} | |||||||||||||||||||||||||||
| 38 | 3 | ▶ | ? '--' . ($mo{$_} || $_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mo{$_} || $_
MC/DC0%0/2
$mo{$_} || $_
$mo{$_}
$_
Truth table0%0/3
A || B
A= $mo{$_}B= $_
| |||||||||||||||||||||||||||||
| 39 | : () | ||||||||||||||||||||||||||||
| 40 | } (qw(delete-after delete delete-excluded))); | ||||||||||||||||||||||||||||
| 41 | push(@command, map { | ||||||||||||||||||||||||||||
| 42 | 1 | $self->{options}{$_} | |||||||||||||||||||||||||||
| 43 | 2 | ▶ | ? ('--' . ($mo{$_} || $_), $self->{options}{$_}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mo{$_} || $_
MC/DC0%0/2
$mo{$_} || $_
$mo{$_}
$_
Truth table0%0/3
A || B
A= $mo{$_}B= $_
| |||||||||||||||||||||||||||||
| 44 | : () | ||||||||||||||||||||||||||||
| 45 | } (qw(partialdir tempdir)) | ||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||
| 47 | 1 | ▶ | push(@command, '--partial') if ($self->{options}{partialdir}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | push(@command, '-e', 'ssh') if ($self->{options}{use_ssh}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | push( @command, | ||||||||||||||||||||||||||||
| 52 | $self->{source}, | ||||||||||||||||||||||||||||
| 53 | $self->{dest} | ||||||||||||||||||||||||||||
| 54 | 1 | ); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | ▶ | $ENV{RSYNC_PASSWORD} = $self->{options}{password} || '-'; # Avoid passwd prompt | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'options'}{'password'} || '-'
MC/DC0%0/1
$self->{'options'}{'password'} || '-'
$self->{'options'}{'password'}
Truth table50%1/2
A
A= $self->{'options'}{'password'}
| |||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | return @command; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub _analyze_output { | ||||||||||||||||||||||||||
|
Subroutine
_analyze_output: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 62 | 0 | my ($self, $src, $line) = @_; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ($src eq 'STDERR') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | 0 | return $line; | |||||||||||||||||||||||||||
| 65 | } elsif ($line =~ /vanished|error|permission denied/i) { | ||||||||||||||||||||||||||||
| 66 | 0 | return $line | |||||||||||||||||||||||||||
| 67 | } else { | ||||||||||||||||||||||||||||
| 68 | 0 | return; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub _exitcode { | ||||||||||||||||||||||||||
|
Subroutine
_exitcode: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 73 | 0 | my ($self, $exitstatus) = @_; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | return 0 if (! $exitstatus); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | # Handle system exit code | ||||||||||||||||||||||||||||
| 77 | # if (grep { ($? & 127) == $_ } ()) { | ||||||||||||||||||||||||||||
| 78 | # } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | # Rsync exit code - no way to retry | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | grep { ( $exitstatus ) == $_ } ( | |||||||||||||||||||||||||||
| 83 | 1, # Syntax or usage error | ||||||||||||||||||||||||||||
| 84 | 2, # Protocol incompatibility | ||||||||||||||||||||||||||||
| 85 | 20, # SIGUSR1 ou SIGINT reçu | ||||||||||||||||||||||||||||
| 86 | ) | ||||||||||||||||||||||||||||
| 87 | ) | ||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | return ( 2 ); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # This is not a failure, but normal state | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | grep { ( $exitstatus ) == $_ } ( | |||||||||||||||||||||||||||
| 95 | 25, # The --max-delete limit stopped deletions | ||||||||||||||||||||||||||||
| 96 | ) | ||||||||||||||||||||||||||||
| 97 | ) | ||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 0 | return ( 0 ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | return ( 1 ); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 4 | 1; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||||||||