| 1 | package Tapper::Installer::Precondition::Copyfile; | ||||||||||||||||||||||||||||||||
| 2 | 5 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||||||
| 3 | 5 | $Tapper::Installer::Precondition::Copyfile::VERSION = '5.0.3'; | |||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 5 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | 5 | ▶ | use YAML; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 5 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 5 | extends 'Tapper::Installer::Precondition'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 5 | ▶ | sub install { | ||||||||||||||||||||||||||||||
|
Subroutine
install: called CC=10 SCAR=30.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 16 | 5 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | return ('no filename given to copyfile::install') if not $file->{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 19 | 5 | ▶ | return ('no destination given for '.$file->{name}) if not $file->{dest}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 5 | $file->{dest} = $self->cfg->{paths}{base_dir}.$file->{dest}; | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 5 | ▶ | $self->log->warn("no protocol given, try to use 'local'") and $file->{protocol}='local' if not $file->{protocol}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$file->{'protocol'} || $self->log->warn(q[no protocol given, try to use 'local']) && ($file->{'protocol'} = 'local')
$self->log->warn("no protocol given, try to use 'local'") and $file->{"protocol"} = "local"
MC/DC0%0/2
$file->{'protocol'} || $self->log->warn(q[no protocol given, try to use 'local']) && ($file->{'protocol'} = 'local')
$file->{'protocol'}
$self->log->warn("no protocol given, try to use 'local'")
Truth table33%1/3
A || B
A= $file->{'protocol'}B= $self->log->warn("no protocol given, try to use 'local'")
| |||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 5 | my $retval; | |||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | if ($file->{protocol} eq 'nfs') { | ||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||
| 27 | 0 | $retval = $self->install_nfs($file) | |||||||||||||||||||||||||||||||
| 28 | } elsif ($file->{protocol} eq 'rsync') { | ||||||||||||||||||||||||||||||||
| 29 | 0 | $retval = $self->install_rsync($file) | |||||||||||||||||||||||||||||||
| 30 | } elsif ($file->{protocol} eq 'local') { | ||||||||||||||||||||||||||||||||
| 31 | 5 | $retval = $self->install_local($file) | |||||||||||||||||||||||||||||||
| 32 | } elsif ($file->{protocol} eq 'scp') { | ||||||||||||||||||||||||||||||||
| 33 | 0 | $retval = $self->install_scp($file) | |||||||||||||||||||||||||||||||
| 34 | } else { | ||||||||||||||||||||||||||||||||
| 35 | 0 | return 'File '.$file->{name}.' has unknown protocol type '.$file->{protocol}; | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | 5 | ▶ | $retval = $self->copy_prc($file) if $file->{copy_prc}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | 5 | return $retval; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 5 | ▶ | sub install_local { | ||||||||||||||||||||||||||||||
|
Subroutine
install_local: called CC=5 SCAR=16.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 46 | 5 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 5 | my $dest_filename = ''; # get rid of the "uninitialised" warning | |||||||||||||||||||||||||||||||
| 49 | 5 | my ($dest_path, $retval); | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | 5 | ▶ | if ($file->{dest} =~ m(/$)) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 0 | $dest_path = $file->{dest}; | |||||||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||||||
| 54 | 5 | ($dest_filename, $dest_path, undef) = fileparse($file->{dest}); | |||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | $dest_path .= '/' if $dest_path !~ m(/$); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | 5 | ▶ | return $retval if $retval = $self->makedir($dest_path); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 5 | $self->log->debug("Copying ".$file->{name}." to $dest_path$dest_filename"); | |||||||||||||||||||||||||||||||
| 60 | 5 | my ($error, $message) = $self->log_and_exec("cp","--sparse=always","-r","-L",$file->{name},$dest_path.$dest_filename); | |||||||||||||||||||||||||||||||
| 61 | 5 | ▶ | return "Can't copy ".$file->{name}." to $dest_path$dest_filename:$message" if $error; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 5 | return(0); | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub install_nfs { | ||||||||||||||||||||||||||||||
|
Subroutine
install_nfs: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 0 | my ($filename, $path, $retval, $error); | |||||||||||||||||||||||||||||||
| 72 | 0 | my $nfs_dir='/mnt/nfs'; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( $file->{name} =~ m,/$, ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 75 | 0 | return 'File name is a directory. Installing directory preconditions is not yet supported'; | |||||||||||||||||||||||||||||||
| 76 | } else { | ||||||||||||||||||||||||||||||||
| 77 | 0 | ($filename, $path, undef) = fileparse($file->{name}); | |||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $path .= '/' if $path !~ m,/$,; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $self->makedir($nfs_dir) if not -d $nfs_dir; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | $self->log->debug("mount -a $path $nfs_dir"); | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 0 | ($error, $retval) = $self->log_and_exec("mount $path $nfs_dir"); | |||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return ("Can't mount nfs share $path to $nfs_dir: $retval") if $error; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | 0 | $file->{name} = "$nfs_dir/$filename"; | |||||||||||||||||||||||||||||||
| 88 | 0 | $retval = $self->install_local($file); | |||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | 0 | $self->log_and_exec("umount $nfs_dir"); | |||||||||||||||||||||||||||||||
| 92 | 0 | return $retval; | |||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub install_scp { | ||||||||||||||||||||||||||||||
|
Subroutine
install_scp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 98 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 0 | my $dest = $self->cfg->{paths}{base_dir}.$file->{dest}; | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | #(XXX) Bad solution, find a better one | ||||||||||||||||||||||||||||||||
| 103 | 0 | system("scp","-r",$file->{name},$dest); | |||||||||||||||||||||||||||||||
| 104 | 0 | return $self->install_local($file); | |||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub install_rsync { | ||||||||||||||||||||||||||||||
|
Subroutine
install_rsync: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 0 | return "Not implemented yet."; | |||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 5 | 1; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||