MMM/Sync/Rsync.pm

filter: Statementstmt 55.8% 24 / 43 Branchbran 29.1% 7 / 24 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 60.0% 3 / 5 Podpod 100% 1 / 1 totaltotal 41.8% 36 / 86 CC 17 SCAR 29.7
CC
17
Cov
43%
buildcmd
24.4
_exitcode
20.0
_analyze_output
12.0
CRAP 19.6
« MMM/Report/Console.pm ↑ Summary MMM/Report.pm »
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
BranchTrueFalseTotal
if ($self->{'options'}{'rsync_defaults'}) { } 0 1 1
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
BranchTrueFalseTotal
if ($self->{"options"}{"rsync_opts"}) 0 1 1
23 0 push(@command, split(/ +/, $self->{options}{rsync_opts}));
24 }
25  
26 1 ▶ if ($self->{options}{exclude}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"options"}{"exclude"}) 0 1 1
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
BranchTrueFalseTotal
$self->{'options'}{$_} ? : 0 3 3
Condition0%0/3
$mo{$_} || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$mo{$_} || $_
$mo{$_} $_
Truth table0%0/3
A || B
A= $mo{$_}B= $_
ABresult
1X1
011
000
39 : ()
40 } (qw(delete-after delete delete-excluded)));
41 push(@command, map {
42 1 $self->{options}{$_}
43 2 ▶ ? ('--' . ($mo{$_} || $_), $self->{options}{$_})
Branch: 1 branch
BranchTrueFalseTotal
$self->{'options'}{$_} ? : 0 2 2
Condition0%0/3
$mo{$_} || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$mo{$_} || $_
$mo{$_} $_
Truth table0%0/3
A || B
A= $mo{$_}B= $_
ABresult
1X1
011
000
44 : ()
45 } (qw(partialdir tempdir))
46 );
47 1 ▶ push(@command, '--partial') if ($self->{options}{partialdir});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"partialdir"} 0 1 1
48  
49 1 ▶ push(@command, '-e', 'ssh') if ($self->{options}{use_ssh});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"options"}{"use_ssh"} 0 1 1
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'} || '-'
l!l
01
MC/DC0%0/1
$self->{'options'}{'password'} || '-'
$self->{'options'}{'password'}
Truth table50%1/2
A
A= $self->{'options'}{'password'}
Aresult
11
00
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
BranchTrueFalseTotal
if ($src eq 'STDERR') { } 0 0 0
elsif ($line =~ /vanished|error|permission denied/i) { } 0 0 0
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
BranchTrueFalseTotal
unless $exitstatus 0 0 0
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
BranchTrueFalseTotal
if (grep {$exitstatus == $_;} 1, 2, 20) 0 0 0
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
BranchTrueFalseTotal
if (grep {$exitstatus == $_;} 25) 0 0 0
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__
« MMM/Report/Console.pm ↑ Summary MMM/Report.pm »