line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Storage; |
2
|
|
|
|
|
|
|
|
3
|
36
|
|
|
36
|
|
1418971
|
use strict; |
|
36
|
|
|
|
|
111
|
|
|
36
|
|
|
|
|
1172
|
|
4
|
36
|
|
|
36
|
|
207
|
use warnings; |
|
36
|
|
|
|
|
90
|
|
|
36
|
|
|
|
|
1139
|
|
5
|
|
|
|
|
|
|
|
6
|
36
|
|
|
36
|
|
199
|
use Config; |
|
36
|
|
|
|
|
196
|
|
|
36
|
|
|
|
|
1868
|
|
7
|
36
|
|
|
36
|
|
184
|
use English qw(-no_match_vars); |
|
36
|
|
|
|
|
79
|
|
|
36
|
|
|
|
|
275
|
|
8
|
36
|
|
|
36
|
|
18645
|
use File::Path qw(mkpath); |
|
36
|
|
|
|
|
109
|
|
|
36
|
|
|
|
|
3172
|
|
9
|
36
|
|
|
36
|
|
9054
|
use Storable; |
|
36
|
|
|
|
|
27970
|
|
|
36
|
|
|
|
|
2126
|
|
10
|
|
|
|
|
|
|
|
11
|
36
|
|
|
36
|
|
1428
|
use FusionInventory::Agent::Logger; |
|
36
|
|
|
|
|
68
|
|
|
36
|
|
|
|
|
20795
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
10
|
|
|
10
|
1
|
2064
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
10
|
100
|
|
|
|
44
|
die "no directory parameter" unless $params{directory}; |
17
|
9
|
100
|
|
|
|
230
|
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
|
5
|
|
|
|
|
11
|
eval { |
22
|
5
|
|
|
|
|
915
|
mkpath($params{directory}); |
23
|
|
|
|
|
|
|
}; |
24
|
5
|
50
|
|
|
|
23
|
die "Can't create $params{directory}: $EVAL_ERROR" if $EVAL_ERROR; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
9
|
50
|
|
|
|
159
|
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
|
9
|
|
66
|
|
|
65
|
}; |
36
|
|
|
|
|
|
|
|
37
|
9
|
|
|
|
|
22
|
bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
9
|
|
|
|
|
42
|
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
|
24
|
|
|
24
|
|
67
|
my ($self, %params) = @_; |
50
|
|
|
|
|
|
|
|
51
|
24
|
100
|
|
|
|
97
|
die "no name parameter given" unless $params{name}; |
52
|
|
|
|
|
|
|
|
53
|
20
|
|
|
|
|
106
|
return $self->{directory} . '/' . $params{name} . '.dump'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub has { |
57
|
3
|
|
|
3
|
1
|
967
|
my ($self, %params) = @_; |
58
|
|
|
|
|
|
|
|
59
|
3
|
|
|
|
|
9
|
my $file = $self->_getFilePath(%params); |
60
|
|
|
|
|
|
|
|
61
|
2
|
|
|
|
|
49
|
return -f $file; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub save { |
65
|
9
|
|
|
9
|
1
|
52
|
my ($self, %params) = @_; |
66
|
|
|
|
|
|
|
|
67
|
9
|
|
|
|
|
35
|
my $file = $self->_getFilePath(%params); |
68
|
|
|
|
|
|
|
|
69
|
8
|
50
|
|
|
|
42
|
store($params{data}, $file) or warn; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub restore { |
73
|
10
|
|
|
10
|
1
|
54
|
my ($self, %params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
10
|
|
|
|
|
37
|
my $file = $self->_getFilePath(%params); |
76
|
|
|
|
|
|
|
|
77
|
9
|
100
|
|
|
|
196
|
return unless -f $file; |
78
|
|
|
|
|
|
|
|
79
|
4
|
|
|
|
|
6
|
my $result; |
80
|
4
|
|
|
|
|
6
|
eval { |
81
|
4
|
|
|
|
|
16
|
$result = retrieve($file); |
82
|
|
|
|
|
|
|
}; |
83
|
4
|
50
|
|
|
|
301
|
if ($EVAL_ERROR) { |
84
|
0
|
|
|
|
|
0
|
$self->{logger}->error("Can't read corrupted $file, removing it"); |
85
|
0
|
|
|
|
|
0
|
unlink $file; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
18
|
return $result; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub remove { |
92
|
2
|
|
|
2
|
1
|
33
|
my ($self, %params) = @_; |
93
|
|
|
|
|
|
|
|
94
|
2
|
|
|
|
|
8
|
my $file = $self->_getFilePath(%params); |
95
|
|
|
|
|
|
|
|
96
|
1
|
50
|
|
|
|
134
|
unlink $file or $self->{logger}->error("can't unlink $file"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |