line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
########################################### |
2
|
|
|
|
|
|
|
package Sys::Ramdisk; |
3
|
|
|
|
|
|
|
########################################### |
4
|
1
|
|
|
1
|
|
19435
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
1140
|
use Log::Log4perl qw(:easy); |
|
1
|
|
|
|
|
58249
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
1418
|
use Sysadm::Install qw(:all); |
|
1
|
|
|
|
|
45018
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
308
|
use File::Temp qw(tempdir); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
9
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
914
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %class_mapper = |
14
|
|
|
|
|
|
|
map { $_->[0] => __PACKAGE__ . "::" . $_->[1] } |
15
|
|
|
|
|
|
|
( [linux => "Linux"], |
16
|
|
|
|
|
|
|
[macos => "OSX"], |
17
|
|
|
|
|
|
|
[osx => "OSX"], |
18
|
|
|
|
|
|
|
[darwin => "OSX"], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
########################################### |
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
########################################### |
24
|
1
|
|
|
1
|
1
|
541
|
my($class, %options) = @_; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
12
|
my $self = { |
27
|
|
|
|
|
|
|
cleanup => 1, |
28
|
|
|
|
|
|
|
%options, |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
17
|
if(! defined $self->{dir}) { |
32
|
1
|
|
|
|
|
11
|
$self->{dir} = tempdir( CLEANUP => 1 ); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
1
|
50
|
|
|
|
658
|
if(! defined $self->{size}) { |
36
|
1
|
|
|
|
|
9
|
$self->{size} = "100m"; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
6
|
my $subclass = os_class_find(); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
206
|
eval "require $subclass"; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
7
|
bless $self, $subclass; |
44
|
|
|
|
|
|
|
|
45
|
1
|
|
|
|
|
7
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
########################################### |
49
|
|
|
|
|
|
|
sub os_supported_list { |
50
|
|
|
|
|
|
|
########################################### |
51
|
0
|
|
|
0
|
0
|
0
|
(my $path = __PACKAGE__) =~ s/::/\//g; |
52
|
0
|
|
|
|
|
0
|
$path = "$path.pm"; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $dir = $INC{$path}; |
55
|
0
|
|
|
|
|
0
|
$dir =~ s/\.pm$//; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
0
|
my @classes = (); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
0
|
opendir DIR, "$dir" or LOGDIE "Cannot opendir $dir ($!)"; |
60
|
0
|
|
|
|
|
0
|
for my $dir (readdir DIR) { |
61
|
0
|
0
|
|
|
|
0
|
next if $dir eq "."; |
62
|
0
|
0
|
|
|
|
0
|
next if $dir eq ".."; |
63
|
0
|
|
|
|
|
0
|
$dir =~ s/\.pm$//; |
64
|
0
|
|
|
|
|
0
|
push @classes, $dir; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
0
|
closedir DIR; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
return @classes; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
########################################### |
73
|
|
|
|
|
|
|
sub os_find { |
74
|
|
|
|
|
|
|
########################################### |
75
|
3
|
|
|
3
|
0
|
188
|
my $uname = bin_find("uname"); |
76
|
|
|
|
|
|
|
|
77
|
3
|
50
|
|
|
|
812
|
if(! defined $uname) { |
78
|
0
|
|
|
|
|
0
|
LOGWARN "uname command not found in PATH"; |
79
|
0
|
|
|
|
|
0
|
return undef; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
14
|
my($uname_info) = tap $uname; |
83
|
3
|
|
|
|
|
34329
|
chomp $uname_info; |
84
|
|
|
|
|
|
|
|
85
|
3
|
50
|
33
|
|
|
55
|
if(! defined $uname or length $uname == 0) { |
86
|
0
|
|
|
|
|
0
|
LOGWARN "uname didn't return anything meaningful"; |
87
|
0
|
|
|
|
|
0
|
return undef; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
3
|
|
|
|
|
51
|
return $uname_info; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
########################################### |
94
|
|
|
|
|
|
|
sub os_class_find { |
95
|
|
|
|
|
|
|
########################################### |
96
|
2
|
|
|
2
|
0
|
40
|
my $os = os_find(); |
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
14
|
my $keyword = lc $os; |
99
|
|
|
|
|
|
|
|
100
|
2
|
50
|
|
|
|
28
|
if(exists $class_mapper{ $keyword }) { |
101
|
2
|
|
|
|
|
11
|
my $class = $class_mapper{ $keyword }; |
102
|
|
|
|
|
|
|
|
103
|
2
|
|
|
|
|
33
|
DEBUG "Found class $class"; |
104
|
2
|
|
|
|
|
46
|
return $class; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
0
|
WARN "OS '$os' not supported (yet). Please contact the maintainer"; |
108
|
0
|
|
|
|
|
0
|
return undef; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
########################################### |
112
|
|
|
|
|
|
|
sub dir { |
113
|
|
|
|
|
|
|
########################################### |
114
|
1
|
|
|
1
|
1
|
39
|
my($self, $dir) = @_; |
115
|
|
|
|
|
|
|
|
116
|
1
|
50
|
|
|
|
8
|
if(defined $dir) { |
117
|
0
|
|
|
|
|
0
|
$self->{dir} = $dir; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
8
|
return $self->{dir}; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
########################################### |
124
|
|
|
|
|
|
|
sub DESTROY { |
125
|
|
|
|
|
|
|
########################################### |
126
|
1
|
|
|
1
|
|
868105
|
my($self, $dir) = @_; |
127
|
|
|
|
|
|
|
|
128
|
1
|
50
|
|
|
|
19
|
$self->unmount() if $self->{cleanup}; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
########################################### |
132
|
|
|
|
|
|
|
sub size_normalize { |
133
|
|
|
|
|
|
|
########################################### |
134
|
0
|
|
|
0
|
0
|
|
my($self, $size) = @_; |
135
|
|
|
|
|
|
|
|
136
|
0
|
0
|
|
|
|
|
if($size =~ /(\d+)m/) { |
137
|
0
|
|
|
|
|
|
return $1 * 1024 * 1024; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
return $size; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
__END__ |