line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Deploy::Datastore; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
30814573
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
108
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
14
|
use English qw(-no_match_vars); |
|
3
|
|
|
|
|
41
|
|
|
3
|
|
|
|
|
28
|
|
7
|
3
|
|
|
3
|
|
1155
|
use File::Glob; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
171
|
|
8
|
3
|
|
|
3
|
|
10
|
use File::Spec; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
22
|
|
9
|
3
|
|
|
3
|
|
66
|
use File::Path qw(mkpath rmtree); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
139
|
|
10
|
3
|
|
|
3
|
|
10
|
use UNIVERSAL::require; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
19
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
421
|
use FusionInventory::Agent::Tools; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
348
|
|
13
|
3
|
|
|
3
|
|
401
|
use FusionInventory::Agent::Logger; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
135
|
|
14
|
3
|
|
|
3
|
|
1157
|
use FusionInventory::Agent::Task::Deploy::Datastore::WorkDir; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
31
|
|
15
|
3
|
|
|
3
|
|
472
|
use FusionInventory::Agent::Task::Deploy::DiskFree; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1208
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
0
|
|
|
0
|
0
|
|
my ($class, %params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
die "no path parameter" unless $params{path}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $self = { |
23
|
|
|
|
|
|
|
path => File::Spec->rel2abs($params{path}), |
24
|
|
|
|
|
|
|
logger => $params{logger} || |
25
|
0
|
|
0
|
|
|
|
FusionInventory::Agent::Logger->new(), |
26
|
|
|
|
|
|
|
}; |
27
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (!$self->{path}) { |
29
|
0
|
|
|
|
|
|
die("No datastore path"); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
bless $self, $class; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub cleanUp { |
38
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
return unless -d $self->{path}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @storageDirs; |
43
|
0
|
|
|
|
|
|
push @storageDirs, File::Glob::glob($self->{path}.'/fileparts/private/*'); |
44
|
0
|
|
|
|
|
|
push @storageDirs, File::Glob::glob($self->{path}.'/fileparts/shared/*'); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $diskFull=$self->diskIsFull(); |
47
|
0
|
0
|
|
|
|
|
if (-d $self->{path}.'/workdir/') { |
48
|
0
|
|
|
|
|
|
remove_tree( $self->{path}.'/workdir/', {error => \my $err} ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
foreach my $dir (@storageDirs) { |
52
|
|
|
|
|
|
|
|
53
|
0
|
0
|
|
|
|
|
if (!-d $dir) { |
54
|
0
|
|
|
|
|
|
unlink $dir; |
55
|
0
|
|
|
|
|
|
next; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
next unless $dir =~ /(\d+)$/; |
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
0
|
|
|
|
if (time > $1 || $diskFull) { |
61
|
0
|
|
|
|
|
|
remove_tree( $dir, {error => \my $err} ); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub createWorkDir { |
68
|
0
|
|
|
0
|
0
|
|
my ($self, $uuid) = @_; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# mkpath($filePath); |
71
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
|
my $path = $self->{path}.'/workdir/'.$uuid; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
mkpath($path); |
75
|
0
|
0
|
|
|
|
|
return unless -d $path; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return FusionInventory::Agent::Task::Deploy::Datastore::WorkDir->new( |
78
|
|
|
|
|
|
|
path => $path, |
79
|
|
|
|
|
|
|
logger => $self->{logger} |
80
|
0
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub diskIsFull { |
84
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $logger = $self->{logger}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $freeSpace = getFreeSpace( |
89
|
|
|
|
|
|
|
path => $self->{path}, |
90
|
0
|
|
|
|
|
|
logger => $logger |
91
|
|
|
|
|
|
|
); |
92
|
|
|
|
|
|
|
|
93
|
0
|
0
|
|
|
|
|
if (!$freeSpace) { |
94
|
0
|
|
|
|
|
|
$logger->debug('$spaceFree is undef!'); |
95
|
0
|
|
|
|
|
|
$freeSpace = 0; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$logger->debug("Free space on $self->{path}: $freeSpace"); |
99
|
|
|
|
|
|
|
# 400MB Free, should be set by a config option |
100
|
0
|
|
|
|
|
|
return ($freeSpace < 2000); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# imported from File-Path-2.09 |
104
|
|
|
|
|
|
|
sub remove_tree { |
105
|
0
|
0
|
0
|
0
|
0
|
|
push @_, {} unless @_ and UNIVERSAL::isa($_[-1],'HASH'); |
106
|
0
|
|
|
|
|
|
goto &rmtree; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
1; |