| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::Fs::Local; |
|
6
|
|
|
|
|
|
|
|
|
7
|
19
|
|
|
19
|
|
341
|
use v5.12.5; |
|
|
19
|
|
|
|
|
110
|
|
|
8
|
19
|
|
|
19
|
|
156
|
use warnings; |
|
|
19
|
|
|
|
|
77
|
|
|
|
19
|
|
|
|
|
1442
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
19
|
|
|
19
|
|
277
|
use Rex::Interface::Fs::Base; |
|
|
19
|
|
|
|
|
66
|
|
|
|
19
|
|
|
|
|
258
|
|
|
13
|
19
|
|
|
19
|
|
752
|
use base qw(Rex::Interface::Fs::Base); |
|
|
19
|
|
|
|
|
72
|
|
|
|
19
|
|
|
|
|
2064
|
|
|
14
|
19
|
|
|
19
|
|
259
|
use Rex::Helper::File::Stat; |
|
|
19
|
|
|
|
|
61
|
|
|
|
19
|
|
|
|
|
258
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
|
17
|
1048
|
|
|
1048
|
0
|
4672
|
my $that = shift; |
|
18
|
1048
|
|
33
|
|
|
7942
|
my $proto = ref($that) || $that; |
|
19
|
1048
|
|
|
|
|
9554
|
my $self = $proto->SUPER::new(@_); |
|
20
|
|
|
|
|
|
|
|
|
21
|
1048
|
|
|
|
|
3702
|
bless( $self, $proto ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
1048
|
|
|
|
|
4112
|
return $self; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub upload { |
|
27
|
3
|
|
|
3
|
0
|
52
|
my ( $self, $source, $target ) = @_; |
|
28
|
3
|
|
|
|
|
165
|
$self->cp( $source, $target ); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub download { |
|
32
|
0
|
|
|
0
|
0
|
0
|
my ( $self, $source, $target ) = @_; |
|
33
|
0
|
|
|
|
|
0
|
$self->cp( $source, $target ); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub ls { |
|
37
|
3
|
|
|
3
|
0
|
956
|
my ( $self, $path ) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
12
|
my @ret; |
|
40
|
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
9
|
eval { |
|
42
|
3
|
50
|
|
|
|
180
|
opendir( my $dh, $path ) or die("$path is not a directory"); |
|
43
|
3
|
|
|
|
|
164
|
while ( my $entry = readdir($dh) ) { |
|
44
|
33
|
100
|
|
|
|
136
|
next if ( $entry =~ /^\.\.?$/ ); |
|
45
|
27
|
|
|
|
|
89
|
push @ret, $entry; |
|
46
|
|
|
|
|
|
|
} |
|
47
|
3
|
|
|
|
|
122
|
closedir($dh); |
|
48
|
|
|
|
|
|
|
}; |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# failed open directory, return undef |
|
51
|
|
|
|
|
|
|
|
|
52
|
3
|
50
|
33
|
|
|
37
|
die "Error listing directory content ($path)" |
|
53
|
|
|
|
|
|
|
if ( $@ && Rex::Config->get_autodie ); |
|
54
|
3
|
50
|
|
|
|
27
|
if ($@) { return; } |
|
|
0
|
|
|
|
|
0
|
|
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# return directory content |
|
57
|
3
|
|
|
|
|
22
|
return @ret; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub rmdir { |
|
61
|
3
|
|
|
3
|
0
|
18
|
my ( $self, @dirs ) = @_; |
|
62
|
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
34
|
Rex::Logger::debug( "Removing directories: " . join( ", ", @dirs ) ); |
|
64
|
3
|
|
|
|
|
43
|
my $exec = Rex::Interface::Exec->create; |
|
65
|
3
|
50
|
|
|
|
21
|
if ( $^O =~ m/^MSWin/ ) { |
|
66
|
0
|
|
|
|
|
0
|
for (@dirs) { |
|
67
|
0
|
|
|
|
|
0
|
s/\//\\/g; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
0
|
|
|
|
|
0
|
$exec->exec( "rd /Q /S " . join( " ", @dirs ) ); |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
else { |
|
72
|
3
|
|
|
|
|
26
|
@dirs = $self->_normalize_path(@dirs); |
|
73
|
3
|
|
|
|
|
69
|
$exec->exec( "/bin/rm -rf " . join( " ", @dirs ) ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
3
|
50
|
|
|
|
109
|
if ( $? == 0 ) { return 1; } |
|
|
3
|
|
|
|
|
115
|
|
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
die( "Error removing directory: " . join( ", ", @dirs ) ) |
|
79
|
|
|
|
|
|
|
if ( Rex::Config->get_autodie ); |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub is_dir { |
|
83
|
284
|
|
|
284
|
0
|
1295
|
my ( $self, $path ) = @_; |
|
84
|
284
|
100
|
|
|
|
7587
|
( -d $path ) ? return 1 : return undef; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_file { |
|
88
|
681
|
|
|
681
|
0
|
3221
|
my ( $self, $file ) = @_; |
|
89
|
681
|
100
|
33
|
|
|
34659
|
( -f $file || -l $file || -b $file || -c $file || -p $file || -S $file ) |
|
90
|
|
|
|
|
|
|
? return 1 |
|
91
|
|
|
|
|
|
|
: return undef; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub unlink { |
|
95
|
12
|
|
|
12
|
0
|
140
|
my ( $self, @files ) = @_; |
|
96
|
12
|
|
|
|
|
118
|
for my $file (@files) { |
|
97
|
12
|
50
|
|
|
|
1374
|
if ( CORE::unlink($file) == 0 ) { |
|
98
|
0
|
0
|
|
|
|
0
|
die "Error unlinking file: $file" if ( Rex::Config->get_autodie ); |
|
99
|
0
|
|
|
|
|
0
|
return 0; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
12
|
|
|
|
|
112
|
return 1; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub mkdir { |
|
107
|
6
|
|
|
6
|
0
|
19
|
my ( $self, $dir ) = @_; |
|
108
|
6
|
50
|
|
|
|
690
|
if ( CORE::mkdir($dir) == 0 ) { |
|
109
|
0
|
0
|
|
|
|
0
|
die "Error creating directory: $dir" if ( Rex::Config->get_autodie ); |
|
110
|
0
|
|
|
|
|
0
|
return 0; |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
6
|
|
|
|
|
54
|
return 1; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub stat { |
|
117
|
141
|
|
|
141
|
0
|
964
|
my ( $self, $file ) = @_; |
|
118
|
|
|
|
|
|
|
|
|
119
|
141
|
100
|
|
|
|
3862
|
if ( |
|
120
|
|
|
|
|
|
|
my ( |
|
121
|
|
|
|
|
|
|
$dev, $ino, $mode, $nlink, $uid, $gid, $rdev, |
|
122
|
|
|
|
|
|
|
$size, $atime, $mtime, $ctime, $blksize, $blocks |
|
123
|
|
|
|
|
|
|
) |
|
124
|
|
|
|
|
|
|
= CORE::stat($file) |
|
125
|
|
|
|
|
|
|
) |
|
126
|
|
|
|
|
|
|
{ |
|
127
|
|
|
|
|
|
|
|
|
128
|
139
|
|
|
|
|
518
|
my %ret; |
|
129
|
|
|
|
|
|
|
|
|
130
|
139
|
|
|
|
|
4617
|
$ret{'mode'} = sprintf( "%04o", Rex::Helper::File::Stat->S_IMODE($mode) ); |
|
131
|
139
|
|
|
|
|
1048
|
$ret{'size'} = $size; |
|
132
|
139
|
|
|
|
|
537
|
$ret{'uid'} = $uid; |
|
133
|
139
|
|
|
|
|
914
|
$ret{'gid'} = $gid; |
|
134
|
139
|
|
|
|
|
915
|
$ret{'atime'} = $atime; |
|
135
|
139
|
|
|
|
|
557
|
$ret{'mtime'} = $mtime; |
|
136
|
|
|
|
|
|
|
|
|
137
|
139
|
|
|
|
|
2658
|
return %ret; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
2
|
|
|
|
|
13
|
return undef; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub is_readable { |
|
144
|
2
|
|
|
2
|
0
|
6
|
my ( $self, $file ) = @_; |
|
145
|
2
|
50
|
|
|
|
45
|
if ( -r $file ) { return 1; } |
|
|
2
|
|
|
|
|
18
|
|
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub is_writable { |
|
149
|
1
|
|
|
1
|
0
|
14
|
my ( $self, $file ) = @_; |
|
150
|
1
|
50
|
|
|
|
45
|
if ( -w $file ) { return 1; } |
|
|
1
|
|
|
|
|
15
|
|
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub readlink { |
|
154
|
49
|
|
|
49
|
0
|
411
|
my ( $self, $file ) = @_; |
|
155
|
49
|
|
|
|
|
1352
|
return CORE::readlink($file); |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub rename { |
|
159
|
38
|
|
|
38
|
0
|
530
|
my ( $self, $old, $new ) = @_; |
|
160
|
|
|
|
|
|
|
|
|
161
|
38
|
|
|
|
|
1805
|
my $exec = Rex::Interface::Exec->create; |
|
162
|
|
|
|
|
|
|
|
|
163
|
38
|
50
|
|
|
|
1008
|
if ( $^O =~ m/^MSWin/ ) { |
|
164
|
0
|
|
|
|
|
0
|
$old =~ s/\//\\/g; |
|
165
|
0
|
|
|
|
|
0
|
$new =~ s/\//\\/g; |
|
166
|
0
|
|
|
|
|
0
|
$exec->exec("move \"$old\" \"$new\""); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
else { |
|
169
|
38
|
|
|
|
|
870
|
($old) = $self->_normalize_path($old); |
|
170
|
38
|
|
|
|
|
317
|
($new) = $self->_normalize_path($new); |
|
171
|
38
|
|
|
|
|
712
|
$exec->exec("/bin/mv $old $new"); |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
38
|
50
|
|
|
|
1038
|
if ( $? == 0 ) { return 1; } |
|
|
38
|
|
|
|
|
966
|
|
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
die "Error renaming file or directory: $old -> $new" |
|
177
|
|
|
|
|
|
|
if ( Rex::Config->get_autodie ); |
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub glob { |
|
181
|
0
|
|
|
0
|
0
|
|
my ( $self, $glob ) = @_; |
|
182
|
0
|
|
|
|
|
|
return CORE::glob($glob); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |