line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Deploy::Datastore::WorkDir; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
129858969
|
use strict; |
|
4
|
|
|
|
|
18
|
|
|
4
|
|
|
|
|
175
|
|
4
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
201
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
7475
|
use Compress::Zlib; |
|
4
|
|
|
|
|
307517
|
|
|
4
|
|
|
|
|
1356
|
|
7
|
4
|
|
|
4
|
|
37
|
use English qw(-no_match_vars); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
47
|
|
8
|
4
|
|
|
4
|
|
2163
|
use File::Path qw(mkpath); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
328
|
|
9
|
4
|
|
|
4
|
|
22
|
use UNIVERSAL::require; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
41
|
|
10
|
4
|
|
|
4
|
|
859
|
use FusionInventory::Agent::Tools; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
952
|
|
11
|
4
|
|
|
4
|
|
26
|
use Encode; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
4291
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
0
|
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $self = { |
17
|
|
|
|
|
|
|
path => $params{path}, |
18
|
|
|
|
|
|
|
logger => $params{logger}, |
19
|
0
|
|
|
|
|
|
files => [] |
20
|
|
|
|
|
|
|
}; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
if (! -d $self->{path}) { |
23
|
0
|
|
|
|
|
|
die "path `".$self->{path}."' doesn't exit."; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
bless $self, $class; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub addFile { |
31
|
0
|
|
|
0
|
0
|
|
my ($self, $file) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
push @{$self->{files}}, $file; |
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub prepare { |
38
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $logger = $self->{logger}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Rebuild the complet file from the filepart |
43
|
0
|
|
|
|
|
|
foreach my $file (@{$self->{files}}) { |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$file->{name_local} = $file->{name}; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ($OSNAME eq 'MSWin32') { |
47
|
0
|
|
|
|
|
|
FusionInventory::Agent::Tools::Win32->require; |
48
|
0
|
|
|
|
|
|
my $localCodepage = FusionInventory::Agent::Tools::Win32::getLocalCodepage(); |
49
|
0
|
0
|
|
|
|
|
if (Encode::is_utf8($file->{name})) { |
50
|
0
|
|
|
|
|
|
$file->{name_local} = encode($localCodepage, $file->{name}); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# If the file will be extracted, we simplify its name to avoid problem during |
55
|
|
|
|
|
|
|
# the extraction process |
56
|
0
|
0
|
|
|
|
|
if ($file->{uncompress}) { |
57
|
0
|
|
|
|
|
|
my $shortsha512 = substr($file->{sha512}, 0, 6); |
58
|
0
|
|
|
|
|
|
$file->{name_local} =~ s/.*\.(tar\.gz)/$shortsha512.$1/i; |
59
|
0
|
0
|
|
|
|
|
if (!$1) { |
60
|
0
|
|
|
|
|
|
$file->{name_local} =~ s/.*\.(tar|gz|7z|bz2)/$shortsha512.$1/i |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $finalFilePath = $self->{path}.'/'.$file->{name_local}; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $fh; |
68
|
0
|
0
|
|
|
|
|
if (!open($fh, '>', $finalFilePath)) { |
69
|
0
|
|
|
|
|
|
$logger->debug("Failed to open '$finalFilePath': $ERRNO"); |
70
|
0
|
|
|
|
|
|
return; |
71
|
|
|
|
|
|
|
} |
72
|
0
|
|
|
|
|
|
binmode($fh); |
73
|
0
|
|
|
|
|
|
foreach my $sha512 (@{$file->{multiparts}}) { |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
my $partFilePath = $file->getPartFilePath($sha512); |
75
|
0
|
0
|
|
|
|
|
if (! -f $partFilePath) { |
76
|
0
|
|
|
|
|
|
$logger->debug("Missing multipart element '$partFilePath'"); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $part; |
80
|
|
|
|
|
|
|
my $buf; |
81
|
0
|
0
|
|
|
|
|
if ($part = gzopen($partFilePath, 'rb')) { |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$logger->debug("reading $sha512"); |
84
|
0
|
|
|
|
|
|
while ($part->gzread($buf, 1024) > 0) { |
85
|
0
|
|
|
|
|
|
print $fh $buf; |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
$part->gzclose; |
88
|
|
|
|
|
|
|
} else { |
89
|
0
|
|
|
|
|
|
$logger->info("Failed to open '$partFilePath'"); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} |
92
|
0
|
|
|
|
|
|
close($fh); |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
if (!$file->validateFileByPath($finalFilePath)) { |
95
|
0
|
|
|
|
|
|
$logger->info("Failed to construct the final file.: $finalFilePath"); |
96
|
0
|
|
|
|
|
|
return; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# Now uncompress |
102
|
0
|
|
|
|
|
|
foreach my $file (@{$self->{files}}) { |
|
0
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
|
my $finalFilePath = $self->{path}.'/'.$file->{name_local}; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ($file->{uncompress}) { |
106
|
0
|
0
|
|
|
|
|
if(canRun('7z')) { |
107
|
0
|
|
|
|
|
|
my $tarball; |
108
|
0
|
|
|
|
|
|
foreach (`7z x -o\"$self->{path}\" \"$finalFilePath\"`) { |
109
|
0
|
|
|
|
|
|
chomp; |
110
|
0
|
|
|
|
|
|
$logger->debug2("7z: $_"); |
111
|
0
|
0
|
|
|
|
|
if (/Extracting\s+(.*\.tar)$/) { |
112
|
0
|
|
|
|
|
|
$tarball = $1; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
0
|
|
|
|
if ($tarball && ($finalFilePath =~ /tgz$/i || $finalFilePath =~ /tar\.(gz|xz|bz2)$/i)) { |
|
|
|
0
|
|
|
|
|
116
|
0
|
|
|
|
|
|
foreach (`7z x -o\"$self->{path}\" \"$self->{path}/$tarball\"`) { |
117
|
0
|
|
|
|
|
|
chomp; |
118
|
0
|
|
|
|
|
|
$logger->debug2("7z: $_"); |
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
|
|
|
unlink($self->{path}.'/'.$tarball); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} else { |
123
|
0
|
|
|
|
|
|
Archive::Extract->require; |
124
|
0
|
|
|
|
|
|
$Archive::Extract::DEBUG=1; |
125
|
0
|
|
|
|
|
|
my $ae = Archive::Extract->new( archive => $finalFilePath ); |
126
|
0
|
0
|
|
|
|
|
if (!$ae) { |
|
|
0
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
$logger->info("Failed to create Archive::Extract object"); |
128
|
|
|
|
|
|
|
} elsif (!$ae->extract( to => $self->{path} )) { |
129
|
0
|
|
|
|
|
|
$logger->debug("Failed to extract '$finalFilePath'"); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
# We ignore failure here because one my have activated the |
132
|
|
|
|
|
|
|
# extract flag on common file and this should be harmless |
133
|
|
|
|
|
|
|
} |
134
|
0
|
|
|
|
|
|
unlink($finalFilePath); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return 1; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |