line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
2
|
|
|
|
|
|
|
$Tapper::Installer::Precondition::Copyfile::VERSION = '5.0.1'; |
3
|
|
|
|
|
|
|
use strict; |
4
|
3
|
|
|
3
|
|
20
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
79
|
|
5
|
3
|
|
|
3
|
|
13
|
|
|
3
|
|
|
|
|
19
|
|
|
3
|
|
|
|
|
69
|
|
6
|
|
|
|
|
|
|
use Moose; |
7
|
3
|
|
|
3
|
|
15
|
use YAML; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
18
|
|
8
|
3
|
|
|
3
|
|
17417
|
use File::Basename; |
|
3
|
|
|
|
|
11625
|
|
|
3
|
|
|
|
|
138
|
|
9
|
3
|
|
|
3
|
|
20
|
extends 'Tapper::Installer::Precondition'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2090
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my ($self, $file) = @_; |
15
|
|
|
|
|
|
|
|
16
|
5
|
|
|
5
|
1
|
12
|
return ('no filename given to copyfile::install') if not $file->{name}; |
17
|
|
|
|
|
|
|
return ('no destination given for '.$file->{name}) if not $file->{dest}; |
18
|
5
|
50
|
|
|
|
13
|
|
19
|
5
|
50
|
|
|
|
10
|
$file->{dest} = $self->cfg->{paths}{base_dir}.$file->{dest}; |
20
|
|
|
|
|
|
|
|
21
|
5
|
|
|
|
|
101
|
$self->log->warn("no protocol given, try to use 'local'") and $file->{protocol}='local' if not $file->{protocol}; |
22
|
|
|
|
|
|
|
|
23
|
5
|
50
|
0
|
|
|
12
|
my $retval; |
24
|
|
|
|
|
|
|
if ($file->{protocol} eq 'nfs') { |
25
|
5
|
|
|
|
|
7
|
$retval = $self->install_nfs($file) |
26
|
5
|
50
|
|
|
|
20
|
} elsif ($file->{protocol} eq 'rsync') { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
$retval = $self->install_rsync($file) |
28
|
|
|
|
|
|
|
} elsif ($file->{protocol} eq 'local') { |
29
|
0
|
|
|
|
|
0
|
$retval = $self->install_local($file) |
30
|
|
|
|
|
|
|
} elsif ($file->{protocol} eq 'scp') { |
31
|
5
|
|
|
|
|
14
|
$retval = $self->install_scp($file) |
32
|
|
|
|
|
|
|
} else { |
33
|
0
|
|
|
|
|
0
|
return 'File '.$file->{name}.' has unknown protocol type '.$file->{protocol}; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
0
|
|
36
|
|
|
|
|
|
|
$retval = $self->copy_prc($file) if $file->{copy_prc}; |
37
|
|
|
|
|
|
|
return $retval; |
38
|
5
|
50
|
|
|
|
15
|
} |
39
|
5
|
|
|
|
|
23
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my ($self, $file) = @_; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $dest_filename = ''; # get rid of the "uninitialised" warning |
46
|
5
|
|
|
5
|
1
|
9
|
my ($dest_path, $retval); |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
7
|
if ($file->{dest} =~ m(/$)) { |
49
|
5
|
|
|
|
|
18
|
$dest_path = $file->{dest}; |
50
|
|
|
|
|
|
|
} else { |
51
|
5
|
50
|
|
|
|
20
|
($dest_filename, $dest_path, undef) = fileparse($file->{dest}); |
52
|
0
|
|
|
|
|
0
|
$dest_path .= '/' if $dest_path !~ m(/$); |
53
|
|
|
|
|
|
|
} |
54
|
5
|
|
|
|
|
102
|
return $retval if $retval = $self->makedir($dest_path); |
55
|
5
|
50
|
|
|
|
22
|
|
56
|
|
|
|
|
|
|
$self->log->debug("Copying ".$file->{name}." to $dest_path$dest_filename"); |
57
|
5
|
50
|
|
|
|
20
|
my ($error, $message) = $self->log_and_exec("cp","--sparse=always","-r","-L",$file->{name},$dest_path.$dest_filename); |
58
|
|
|
|
|
|
|
return "Can't copy ".$file->{name}." to $dest_path$dest_filename:$message" if $error; |
59
|
5
|
|
|
|
|
5109
|
|
60
|
5
|
|
|
|
|
579
|
return(0); |
61
|
5
|
50
|
|
|
|
48
|
} |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
19
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my ($self, $file) = @_; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my ($filename, $path, $retval, $error); |
68
|
|
|
|
|
|
|
my $nfs_dir='/mnt/nfs'; |
69
|
0
|
|
|
0
|
1
|
|
|
70
|
|
|
|
|
|
|
if ( $file->{name} =~ m,/$, ) { |
71
|
0
|
|
|
|
|
|
return 'File name is a directory. Installing directory preconditions is not yet supported'; |
72
|
0
|
|
|
|
|
|
} else { |
73
|
|
|
|
|
|
|
($filename, $path, undef) = fileparse($file->{name}); |
74
|
0
|
0
|
|
|
|
|
$path .= '/' if $path !~ m,/$,; |
75
|
0
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
$self->makedir($nfs_dir) if not -d $nfs_dir; |
78
|
0
|
0
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->log->debug("mount -a $path $nfs_dir"); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
($error, $retval) = $self->log_and_exec("mount $path $nfs_dir"); |
82
|
|
|
|
|
|
|
return ("Can't mount nfs share $path to $nfs_dir: $retval") if $error; |
83
|
0
|
|
|
|
|
|
$file->{name} = "$nfs_dir/$filename"; |
84
|
|
|
|
|
|
|
$retval = $self->install_local($file); |
85
|
0
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->log_and_exec("umount $nfs_dir"); |
88
|
0
|
|
|
|
|
|
return $retval; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my ($self, $file) = @_; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
my $dest = $self->cfg->{paths}{base_dir}.$file->{dest}; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
#(XXX) Bad solution, find a better one |
98
|
0
|
|
|
0
|
1
|
|
system("scp","-r",$file->{name},$dest); |
99
|
|
|
|
|
|
|
return $self->install_local($file); |
100
|
0
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my ($self, $file) = @_; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return "Not implemented yet."; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
1
|
|
|
113
|
|
|
|
|
|
|
1; |
114
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=pod |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=encoding UTF-8 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 NAME |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Tapper::Installer::Precondition::Copyfile |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SYNOPSIS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
use Tapper::Installer::Precondition::Copyfile; |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 NAME |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Tapper::Installer::Precondition::Copyfile - Install a file to a given location |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 FUNCTIONS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 install |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This function encapsulates installing one single file. scp, nfs and |
137
|
|
|
|
|
|
|
local are supported protocols. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
@param hash reference - contains all information about the file |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
@return success - 0 |
142
|
|
|
|
|
|
|
@return error - error string |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head2 install_local |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Install a file from a local source. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
@param hash reference - contains all information about the file |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
@return success - 0 |
151
|
|
|
|
|
|
|
@return error - error string |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 install_nfs |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Install a file from an nfs share. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
@param hash reference - contains all information about the file |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
@return success - 0 |
160
|
|
|
|
|
|
|
@return error - error string |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 install_scp |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Install a file using scp. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
@param hash reference - contains all information about the file |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
@return success - 0 |
169
|
|
|
|
|
|
|
@return error - error string |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 install_rsync |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Install a file using rsync. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
@param hash reference - contains all information about the file |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
@return success - 0 |
178
|
|
|
|
|
|
|
@return error - error string |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 AUTHORS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over 4 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item * |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Advanced Micro Devices, Inc. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
This is free software, licensed under: |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |