line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Storage; |
2
|
|
|
|
|
|
|
|
3
|
24
|
|
|
24
|
|
1125544
|
use strict; |
|
24
|
|
|
|
|
47
|
|
|
24
|
|
|
|
|
1059
|
|
4
|
24
|
|
|
24
|
|
126
|
use warnings; |
|
24
|
|
|
|
|
51
|
|
|
24
|
|
|
|
|
697
|
|
5
|
|
|
|
|
|
|
|
6
|
24
|
|
|
24
|
|
108
|
use Config; |
|
24
|
|
|
|
|
91
|
|
|
24
|
|
|
|
|
1064
|
|
7
|
24
|
|
|
24
|
|
125
|
use English qw(-no_match_vars); |
|
24
|
|
|
|
|
32
|
|
|
24
|
|
|
|
|
193
|
|
8
|
24
|
|
|
24
|
|
10788
|
use File::Path qw(mkpath); |
|
24
|
|
|
|
|
83
|
|
|
24
|
|
|
|
|
1885
|
|
9
|
24
|
|
|
24
|
|
3666
|
use Storable; |
|
24
|
|
|
|
|
21063
|
|
|
24
|
|
|
|
|
1547
|
|
10
|
|
|
|
|
|
|
|
11
|
24
|
|
|
24
|
|
898
|
use FusionInventory::Agent::Logger; |
|
24
|
|
|
|
|
25
|
|
|
24
|
|
|
|
|
12253
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
die "no directory parameter" unless $params{directory}; |
17
|
0
|
0
|
|
|
|
|
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
|
0
|
|
|
|
|
|
eval { |
22
|
0
|
|
|
|
|
|
mkpath($params{directory}); |
23
|
|
|
|
|
|
|
}; |
24
|
0
|
0
|
|
|
|
|
die "Can't create $params{directory}: $EVAL_ERROR" if $EVAL_ERROR; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (! -w $params{directory}) { |
28
|
0
|
|
|
|
|
|
die "Can't write in $params{directory}"; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
my $self = { |
32
|
|
|
|
|
|
|
logger => $params{logger} || |
33
|
|
|
|
|
|
|
FusionInventory::Agent::Logger->new(), |
34
|
|
|
|
|
|
|
directory => $params{directory} |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
bless $self, $class; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub getDirectory { |
43
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return $self->{directory}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _getFilePath { |
49
|
0
|
|
|
0
|
|
|
my ($self, %params) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
die "no name parameter given" unless $params{name}; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
return $self->{directory} . '/' . $params{name} . '.dump'; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub has { |
57
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $file = $self->_getFilePath(%params); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return -f $file; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub save { |
65
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
my $file = $self->_getFilePath(%params); |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
store($params{data}, $file) or warn; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub restore { |
73
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $file = $self->_getFilePath(%params); |
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
return unless -f $file; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $result; |
80
|
0
|
|
|
|
|
|
eval { |
81
|
0
|
|
|
|
|
|
$result = retrieve($file); |
82
|
|
|
|
|
|
|
}; |
83
|
0
|
0
|
|
|
|
|
if ($EVAL_ERROR) { |
84
|
0
|
|
|
|
|
|
$self->{logger}->error("Can't read corrupted $file, removing it"); |
85
|
0
|
|
|
|
|
|
unlink $file; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $result; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub remove { |
92
|
0
|
|
|
0
|
1
|
|
my ($self, %params) = @_; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $file = $self->_getFilePath(%params); |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
unlink $file or $self->{logger}->error("can't unlink $file"); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
__END__ |