line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Storage; |
2
|
|
|
|
|
|
|
|
3
|
37
|
|
|
37
|
|
989513
|
use strict; |
|
37
|
|
|
|
|
52
|
|
|
37
|
|
|
|
|
900
|
|
4
|
37
|
|
|
37
|
|
120
|
use warnings; |
|
37
|
|
|
|
|
44
|
|
|
37
|
|
|
|
|
817
|
|
5
|
|
|
|
|
|
|
|
6
|
37
|
|
|
37
|
|
113
|
use Config; |
|
37
|
|
|
|
|
122
|
|
|
37
|
|
|
|
|
1332
|
|
7
|
37
|
|
|
37
|
|
129
|
use English qw(-no_match_vars); |
|
37
|
|
|
|
|
40
|
|
|
37
|
|
|
|
|
186
|
|
8
|
37
|
|
|
37
|
|
11525
|
use File::Path qw(mkpath); |
|
37
|
|
|
|
|
52
|
|
|
37
|
|
|
|
|
1919
|
|
9
|
37
|
|
|
37
|
|
1648
|
use Storable; |
|
37
|
|
|
|
|
6588
|
|
|
37
|
|
|
|
|
1804
|
|
10
|
|
|
|
|
|
|
|
11
|
37
|
|
|
37
|
|
1106
|
use FusionInventory::Agent::Logger; |
|
37
|
|
|
|
|
40
|
|
|
37
|
|
|
|
|
14634
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
12
|
|
|
12
|
1
|
2487
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
12
|
100
|
|
|
|
50
|
die "no directory parameter" unless $params{directory}; |
17
|
11
|
100
|
|
|
|
209
|
if (!-d $params{directory}) { |
18
|
|
|
|
|
|
|
# {error => \my $err} is not supported on RHEL 5, |
19
|
|
|
|
|
|
|
# we let mkpath call die() itself |
20
|
|
|
|
|
|
|
# http://forge.fusioninventory.org/issues/1817 |
21
|
7
|
|
|
|
|
13
|
eval { |
22
|
7
|
|
|
|
|
970
|
mkpath($params{directory}); |
23
|
|
|
|
|
|
|
}; |
24
|
7
|
50
|
|
|
|
25
|
die "Can't create $params{directory}: $EVAL_ERROR" if $EVAL_ERROR; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
11
|
50
|
|
|
|
108
|
if (! -w $params{directory}) { |
28
|
0
|
|
|
|
|
0
|
die "Can't write in $params{directory}"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $self = { |
32
|
|
|
|
|
|
|
logger => $params{logger} || |
33
|
|
|
|
|
|
|
FusionInventory::Agent::Logger->new(), |
34
|
|
|
|
|
|
|
directory => $params{directory} |
35
|
11
|
|
66
|
|
|
58
|
}; |
36
|
|
|
|
|
|
|
|
37
|
11
|
|
|
|
|
19
|
bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
11
|
|
|
|
|
39
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub getDirectory { |
43
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
return $self->{directory}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _getFilePath { |
49
|
30
|
|
|
30
|
|
40
|
my ($self, %params) = @_; |
50
|
|
|
|
|
|
|
|
51
|
30
|
100
|
|
|
|
121
|
die "no name parameter given" unless $params{name}; |
52
|
|
|
|
|
|
|
|
53
|
26
|
|
|
|
|
82
|
return $self->{directory} . '/' . $params{name} . '.dump'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub has { |
57
|
3
|
|
|
3
|
1
|
911
|
my ($self, %params) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
8
|
my $file = $self->_getFilePath(%params); |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
45
|
return -f $file; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub save { |
65
|
12
|
|
|
12
|
1
|
57
|
my ($self, %params) = @_; |
66
|
|
|
|
|
|
|
|
67
|
12
|
|
|
|
|
40
|
my $file = $self->_getFilePath(%params); |
68
|
|
|
|
|
|
|
|
69
|
11
|
50
|
|
|
|
42
|
store($params{data}, $file) or warn; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub restore { |
73
|
13
|
|
|
13
|
1
|
45
|
my ($self, %params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
13
|
|
|
|
|
38
|
my $file = $self->_getFilePath(%params); |
76
|
|
|
|
|
|
|
|
77
|
12
|
100
|
|
|
|
198
|
return unless -f $file; |
78
|
|
|
|
|
|
|
|
79
|
5
|
|
|
|
|
5
|
my $result; |
80
|
5
|
|
|
|
|
7
|
eval { |
81
|
5
|
|
|
|
|
15
|
$result = retrieve($file); |
82
|
|
|
|
|
|
|
}; |
83
|
5
|
50
|
|
|
|
281
|
if ($EVAL_ERROR) { |
84
|
0
|
|
|
|
|
0
|
$self->{logger}->error("Can't read corrupted $file, removing it"); |
85
|
0
|
|
|
|
|
0
|
unlink $file; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
5
|
|
|
|
|
16
|
return $result; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub remove { |
92
|
2
|
|
|
2
|
1
|
35
|
my ($self, %params) = @_; |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
5
|
my $file = $self->_getFilePath(%params); |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
120
|
unlink $file or $self->{logger}->error("can't unlink $file"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |