line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rex::Hook::File::Impostor; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: execute Rex file management commands on a copy of the managed path |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
219834
|
use 5.012; |
|
2
|
|
|
|
|
16
|
|
6
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
94
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
12
|
use Digest::MD5; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
109
|
|
9
|
2
|
|
|
2
|
|
13
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
10
|
2
|
|
|
2
|
|
733
|
use File::Basename; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
170
|
|
11
|
2
|
|
|
2
|
|
11
|
use File::Spec; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
12
|
2
|
|
|
2
|
|
660
|
use Rex 1.013004 -base; |
|
2
|
|
|
|
|
59574
|
|
|
2
|
|
|
|
|
14
|
|
13
|
2
|
|
|
2
|
|
526735
|
use Rex::Hook; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
119
|
|
14
|
2
|
|
|
2
|
|
25
|
use Sys::Hostname; |
|
2
|
|
|
|
|
4049
|
|
|
2
|
|
|
|
|
820
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = 'v0.1.1.1'; # TRIAL |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
register_function_hooks { before => { file => \&impostor_hook, }, }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub impostor_hook { |
21
|
5
|
|
|
5
|
0
|
186471
|
my ( $managed_path, @opts ) = @_; |
22
|
|
|
|
|
|
|
|
23
|
5
|
|
|
|
|
151
|
my $impostor_path = get_impostor_for($managed_path); |
24
|
|
|
|
|
|
|
|
25
|
5
|
|
|
|
|
717
|
mkdir dirname($impostor_path); |
26
|
|
|
|
|
|
|
|
27
|
5
|
100
|
|
|
|
91835
|
if ( is_file($managed_path) ) { |
28
|
3
|
|
|
|
|
766
|
Rex::Logger::debug("Copying $managed_path to $impostor_path"); |
29
|
3
|
|
|
|
|
60
|
cp $managed_path, $impostor_path; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
50630
|
return $impostor_path, @opts; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub get_impostor_for { |
36
|
7
|
|
|
7
|
0
|
5620
|
my $path = shift; |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
624
|
my ( $volume, $directories, $file ) = File::Spec->splitpath($path); |
39
|
7
|
|
|
|
|
64
|
$volume =~ s/://gmsx; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
|
|
|
68
|
return File::Spec->join( get_impostor_directory(), $volume, $directories, |
42
|
|
|
|
|
|
|
$file ); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_impostor_directory { |
46
|
9
|
|
|
9
|
0
|
9182
|
my $hasher = Digest::MD5->new(); |
47
|
|
|
|
|
|
|
|
48
|
9
|
|
|
|
|
124
|
$hasher->add(hostname); |
49
|
9
|
|
|
|
|
327
|
$hasher->add($PID); |
50
|
|
|
|
|
|
|
|
51
|
9
|
|
|
|
|
99
|
my $unique_id = $hasher->hexdigest(); |
52
|
|
|
|
|
|
|
|
53
|
9
|
|
|
|
|
324
|
my $impostor_directory = File::Spec->join( Rex::Config->get_tmp_dir(), |
54
|
|
|
|
|
|
|
'rex_hook_file_impostor', $unique_id ); |
55
|
|
|
|
|
|
|
|
56
|
9
|
|
|
|
|
5041
|
mkdir $impostor_directory; |
57
|
9
|
|
|
|
|
224020
|
return $impostor_directory; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |