line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Interface::Fs::Local; |
6
|
|
|
|
|
|
|
|
7
|
53
|
|
|
53
|
|
1177
|
use v5.12.5; |
|
53
|
|
|
|
|
303
|
|
8
|
53
|
|
|
53
|
|
420
|
use warnings; |
|
53
|
|
|
|
|
206
|
|
|
53
|
|
|
|
|
4383
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
53
|
|
|
53
|
|
841
|
use Rex::Interface::Fs::Base; |
|
53
|
|
|
|
|
239
|
|
|
53
|
|
|
|
|
732
|
|
13
|
53
|
|
|
53
|
|
2123
|
use base qw(Rex::Interface::Fs::Base); |
|
53
|
|
|
|
|
248
|
|
|
53
|
|
|
|
|
7077
|
|
14
|
53
|
|
|
53
|
|
737
|
use Rex::Helper::File::Stat; |
|
53
|
|
|
|
|
185
|
|
|
53
|
|
|
|
|
785
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
1260
|
|
|
1260
|
0
|
6547
|
my $that = shift; |
18
|
1260
|
|
33
|
|
|
9189
|
my $proto = ref($that) || $that; |
19
|
1260
|
|
|
|
|
10381
|
my $self = $proto->SUPER::new(@_); |
20
|
|
|
|
|
|
|
|
21
|
1260
|
|
|
|
|
4291
|
bless( $self, $proto ); |
22
|
|
|
|
|
|
|
|
23
|
1260
|
|
|
|
|
4300
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub upload { |
27
|
3
|
|
|
3
|
0
|
35
|
my ( $self, $source, $target ) = @_; |
28
|
3
|
|
|
|
|
98
|
$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
|
566
|
my ( $self, $path ) = @_; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
9
|
my @ret; |
40
|
|
|
|
|
|
|
|
41
|
3
|
|
|
|
|
8
|
eval { |
42
|
3
|
50
|
|
|
|
163
|
opendir( my $dh, $path ) or die("$path is not a directory"); |
43
|
3
|
|
|
|
|
175
|
while ( my $entry = readdir($dh) ) { |
44
|
33
|
100
|
|
|
|
125
|
next if ( $entry =~ /^\.\.?$/ ); |
45
|
27
|
|
|
|
|
90
|
push @ret, $entry; |
46
|
|
|
|
|
|
|
} |
47
|
3
|
|
|
|
|
69
|
closedir($dh); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# failed open directory, return undef |
51
|
|
|
|
|
|
|
|
52
|
3
|
50
|
33
|
|
|
20
|
die "Error listing directory content ($path)" |
53
|
|
|
|
|
|
|
if ( $@ && Rex::Config->get_autodie ); |
54
|
3
|
50
|
|
|
|
22
|
if ($@) { return; } |
|
0
|
|
|
|
|
0
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# return directory content |
57
|
3
|
|
|
|
|
21
|
return @ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub rmdir { |
61
|
3
|
|
|
3
|
0
|
27
|
my ( $self, @dirs ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
3
|
|
|
|
|
32
|
Rex::Logger::debug( "Removing directories: " . join( ", ", @dirs ) ); |
64
|
3
|
|
|
|
|
45
|
my $exec = Rex::Interface::Exec->create; |
65
|
3
|
50
|
|
|
|
24
|
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
|
|
|
|
|
21
|
@dirs = $self->_normalize_path(@dirs); |
73
|
3
|
|
|
|
|
38
|
$exec->exec( "/bin/rm -rf " . join( " ", @dirs ) ); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
50
|
|
|
|
74
|
if ( $? == 0 ) { return 1; } |
|
3
|
|
|
|
|
125
|
|
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
0
|
die( "Error removing directory: " . join( ", ", @dirs ) ) |
79
|
|
|
|
|
|
|
if ( Rex::Config->get_autodie ); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub is_dir { |
83
|
283
|
|
|
283
|
0
|
1122
|
my ( $self, $path ) = @_; |
84
|
283
|
100
|
|
|
|
6323
|
( -d $path ) ? return 1 : return undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub is_file { |
88
|
893
|
|
|
893
|
0
|
3323
|
my ( $self, $file ) = @_; |
89
|
893
|
100
|
33
|
|
|
37843
|
( -f $file || -l $file || -b $file || -c $file || -p $file || -S $file ) |
90
|
|
|
|
|
|
|
? return 1 |
91
|
|
|
|
|
|
|
: return undef; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub unlink { |
95
|
13
|
|
|
13
|
0
|
121
|
my ( $self, @files ) = @_; |
96
|
13
|
|
|
|
|
99
|
for my $file (@files) { |
97
|
13
|
50
|
|
|
|
1264
|
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
|
13
|
|
|
|
|
83
|
return 1; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub mkdir { |
107
|
6
|
|
|
6
|
0
|
27
|
my ( $self, $dir ) = @_; |
108
|
6
|
50
|
|
|
|
9501
|
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
|
838
|
my ( $self, $file ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
141
|
100
|
|
|
|
3035
|
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
|
|
|
|
|
400
|
my %ret; |
129
|
|
|
|
|
|
|
|
130
|
139
|
|
|
|
|
3826
|
$ret{'mode'} = sprintf( "%04o", Rex::Helper::File::Stat->S_IMODE($mode) ); |
131
|
139
|
|
|
|
|
852
|
$ret{'size'} = $size; |
132
|
139
|
|
|
|
|
579
|
$ret{'uid'} = $uid; |
133
|
139
|
|
|
|
|
750
|
$ret{'gid'} = $gid; |
134
|
139
|
|
|
|
|
695
|
$ret{'atime'} = $atime; |
135
|
139
|
|
|
|
|
458
|
$ret{'mtime'} = $mtime; |
136
|
|
|
|
|
|
|
|
137
|
139
|
|
|
|
|
2201
|
return %ret; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
2
|
|
|
|
|
18
|
return undef; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub is_readable { |
144
|
2
|
|
|
2
|
0
|
5
|
my ( $self, $file ) = @_; |
145
|
2
|
50
|
|
|
|
43
|
if ( -r $file ) { return 1; } |
|
2
|
|
|
|
|
19
|
|
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub is_writable { |
149
|
1
|
|
|
1
|
0
|
8
|
my ( $self, $file ) = @_; |
150
|
1
|
50
|
|
|
|
36
|
if ( -w $file ) { return 1; } |
|
1
|
|
|
|
|
7
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub readlink { |
154
|
49
|
|
|
49
|
0
|
382
|
my ( $self, $file ) = @_; |
155
|
49
|
|
|
|
|
1086
|
return CORE::readlink($file); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub rename { |
159
|
38
|
|
|
38
|
0
|
354
|
my ( $self, $old, $new ) = @_; |
160
|
|
|
|
|
|
|
|
161
|
38
|
|
|
|
|
1369
|
my $exec = Rex::Interface::Exec->create; |
162
|
|
|
|
|
|
|
|
163
|
38
|
50
|
|
|
|
911
|
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
|
|
|
|
|
656
|
($old) = $self->_normalize_path($old); |
170
|
38
|
|
|
|
|
184
|
($new) = $self->_normalize_path($new); |
171
|
38
|
|
|
|
|
463
|
$exec->exec("/bin/mv $old $new"); |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
38
|
50
|
|
|
|
755
|
if ( $? == 0 ) { return 1; } |
|
38
|
|
|
|
|
800
|
|
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; |