line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Armadito::Agent::Tools::Dir; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1605646
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
85
|
|
4
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
110
|
|
5
|
2
|
|
|
2
|
|
7
|
use base 'Exporter'; |
|
2
|
|
|
|
|
32
|
|
|
2
|
|
|
|
|
373
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
12
|
use UNIVERSAL::require(); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
30
|
|
8
|
2
|
|
|
2
|
|
1305
|
use Encode; |
|
2
|
|
|
|
|
17366
|
|
|
2
|
|
|
|
|
124
|
|
9
|
2
|
|
|
2
|
|
11
|
use English qw(-no_match_vars); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
10
|
2
|
|
|
2
|
|
797
|
use File::Path qw(make_path remove_tree); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
589
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
13
|
|
|
|
|
|
|
makeDirectory |
14
|
|
|
|
|
|
|
readDirectory |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub makeDirectory { |
18
|
0
|
|
|
0
|
1
|
|
my (%params) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
unless ( -d $params{dirpath} ) { |
21
|
0
|
0
|
|
|
|
|
make_path( $params{dirpath} ) || warn "Can't make path $params{dirpath}"; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub readDirectory { |
26
|
0
|
|
|
0
|
1
|
|
my (%params) = @_; |
27
|
0
|
|
|
|
|
|
my @entries = (); |
28
|
0
|
|
|
|
|
|
my $dh; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
if ( !defined( $params{filter} ) ) { |
31
|
0
|
|
|
|
|
|
$params{filter} = "none"; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( !opendir( $dh, $params{dirpath} ) ) { |
35
|
0
|
|
|
|
|
|
die "unable to readdir $params{dirpath}."; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
while ( readdir $dh ) { |
39
|
0
|
0
|
|
|
|
|
if ( my $selected_entry = _isSelected( $_, %params ) ) { |
40
|
0
|
|
|
|
|
|
push( @entries, $selected_entry ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
closedir $dh; |
45
|
0
|
|
|
|
|
|
return @entries; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _isSelected { |
49
|
0
|
|
|
0
|
|
|
my ( $entry, %params ) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( $params{filter} eq "files-only" ) { |
52
|
0
|
0
|
|
|
|
|
if ( !-f $params{dirpath} . "/" . $entry ) { |
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if ( $params{filter} eq "dirs-only" ) { |
58
|
0
|
0
|
|
|
|
|
if ( !-d $params{dirpath} . "/" . $entry ) { |
59
|
0
|
|
|
|
|
|
return; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
0
|
|
|
|
if ( $entry eq "." || $entry eq ".." ) { |
64
|
0
|
|
|
|
|
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $entry; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
__END__ |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Armadito::Agent::Tools::Dir - Basic functions for directories manipulations used in Armadito Agent. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This module provides some easy to use functions for directories manipulations. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 FUNCTIONS |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 makeDirectory(%params) |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Make directory and its subpaths if needed (mkdir -p). |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=over |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item I<dirpath> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Path of the directory to create. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=back |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 readDirectory(%params) |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Open given directory and read all files. This only read at first level deep. This is not a recursive read. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item I<dirpath> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Path of the directory to read. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|