| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (c) 2014, cPanel, Inc. |
|
2
|
|
|
|
|
|
|
# All rights reserved. |
|
3
|
|
|
|
|
|
|
# http://cpanel.net/ |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the same |
|
6
|
|
|
|
|
|
|
# terms as Perl itself. See the LICENSE file for further details. |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::POSIX::Userland::Test; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
410
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
28
|
|
|
11
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
19
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
3
|
use Filesys::POSIX::Bits; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
236
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Filesys::POSIX::Module (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
516
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @METHODS = qw( |
|
17
|
|
|
|
|
|
|
exists is_file is_dir is_link is_char is_block is_fifo |
|
18
|
|
|
|
|
|
|
is_readable is_writable is_executable |
|
19
|
|
|
|
|
|
|
is_setuid is_setgid |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Filesys::POSIX::Module->export_methods( __PACKAGE__, @METHODS ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 NAME |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Filesys::POSIX::Userland::Test - Inode conditional tests |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Filesys::POSIX; |
|
31
|
|
|
|
|
|
|
use Filesys::POSIX::Mem; |
|
32
|
|
|
|
|
|
|
use Filesys::POSIX::Userland::Test; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $fs = Filesys::POSIX->new(Filesys::POSIX::Real->new, |
|
35
|
|
|
|
|
|
|
'noatime' => 1 |
|
36
|
|
|
|
|
|
|
); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$fs->touch('foo'); |
|
39
|
|
|
|
|
|
|
$fs->is_file('foo'); # returns 1 |
|
40
|
|
|
|
|
|
|
$fs->is_dir('foo'); # returns 0 |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This runtime addon module provides a series of boolean tests in the vein of |
|
45
|
|
|
|
|
|
|
L that allow introspection of the nature of files without explicitly |
|
46
|
|
|
|
|
|
|
having to write boilerplate wrappers around C<$fs-Estat>. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This module exposes the inode-level tests in the L base |
|
49
|
|
|
|
|
|
|
class at a higher, file-oriented level. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 TESTS |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=over |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=item C<$FS-Eexists($path)> |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub exists { |
|
62
|
13
|
|
|
13
|
1
|
2846
|
my ( $self, $path ) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
13
|
|
|
|
|
17
|
my $inode = eval { $self->stat($path) }; |
|
|
13
|
|
|
|
|
27
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
13
|
100
|
|
|
|
267
|
return 0 unless $inode; |
|
67
|
12
|
|
|
|
|
24
|
return 1; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item C<$fs-Eis_file($path)> |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a regular file |
|
73
|
|
|
|
|
|
|
(C<$S_IFREG>). |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub is_file { |
|
78
|
6
|
|
|
6
|
1
|
1179
|
my ( $self, $path ) = @_; |
|
79
|
|
|
|
|
|
|
|
|
80
|
6
|
|
|
|
|
7
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
14
|
|
|
81
|
|
|
|
|
|
|
|
|
82
|
6
|
100
|
|
|
|
232
|
return 0 unless $inode; |
|
83
|
5
|
100
|
|
|
|
17
|
return 0 unless $inode->file; |
|
84
|
1
|
|
|
|
|
4
|
return 1; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item C<$fs-Eis_dir($path)> |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a directory |
|
90
|
|
|
|
|
|
|
(C<$S_IFDIR>). |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub is_dir { |
|
95
|
6
|
|
|
6
|
1
|
1263
|
my ( $self, $path ) = @_; |
|
96
|
|
|
|
|
|
|
|
|
97
|
6
|
|
|
|
|
9
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
15
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
6
|
100
|
|
|
|
281
|
return 0 unless $inode; |
|
100
|
5
|
100
|
|
|
|
8
|
return 0 unless $inode->dir; |
|
101
|
1
|
|
|
|
|
3
|
return 1; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=item C<$fs-Eis_link($path)> |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a symlink |
|
107
|
|
|
|
|
|
|
(C<$S_IFLNK>). |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub is_link { |
|
112
|
7
|
|
|
7
|
1
|
1623
|
my ( $self, $path ) = @_; |
|
113
|
|
|
|
|
|
|
|
|
114
|
7
|
|
|
|
|
10
|
my $inode = eval { $self->lstat($path) }; |
|
|
7
|
|
|
|
|
18
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
7
|
100
|
|
|
|
226
|
return 0 unless $inode; |
|
117
|
6
|
100
|
|
|
|
12
|
return 0 unless $inode->link; |
|
118
|
1
|
|
|
|
|
3
|
return 1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item C<$fs-Eis_char($path)> |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a character device |
|
124
|
|
|
|
|
|
|
(C<$S_IFCHR>). |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub is_char { |
|
129
|
6
|
|
|
6
|
1
|
1283
|
my ( $self, $path ) = @_; |
|
130
|
|
|
|
|
|
|
|
|
131
|
6
|
|
|
|
|
6
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
13
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
6
|
100
|
|
|
|
234
|
return 0 unless $inode; |
|
134
|
5
|
100
|
|
|
|
16
|
return 0 unless $inode->char; |
|
135
|
1
|
|
|
|
|
2
|
return 1; |
|
136
|
|
|
|
|
|
|
} |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item C<$fs-Eis_block($path)> |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a block device |
|
141
|
|
|
|
|
|
|
(C<$S_IFBLK>). |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub is_block { |
|
146
|
6
|
|
|
6
|
1
|
1281
|
my ( $self, $path ) = @_; |
|
147
|
|
|
|
|
|
|
|
|
148
|
6
|
|
|
|
|
7
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
15
|
|
|
149
|
|
|
|
|
|
|
|
|
150
|
6
|
100
|
|
|
|
239
|
return 0 unless $inode; |
|
151
|
5
|
100
|
|
|
|
19
|
return 0 unless $inode->block; |
|
152
|
1
|
|
|
|
|
4
|
return 1; |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item C<$fs-Eis_fifo($path)> |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and is a FIFO |
|
158
|
|
|
|
|
|
|
(C<$S_IFIFO>). |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub is_fifo { |
|
163
|
6
|
|
|
6
|
1
|
1139
|
my ( $self, $path ) = @_; |
|
164
|
|
|
|
|
|
|
|
|
165
|
6
|
|
|
|
|
7
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
14
|
|
|
166
|
|
|
|
|
|
|
|
|
167
|
6
|
100
|
|
|
|
267
|
return 0 unless $inode; |
|
168
|
5
|
100
|
|
|
|
18
|
return 0 unless $inode->fifo; |
|
169
|
1
|
|
|
|
|
3
|
return 1; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item C<$fs-Eis_readable($path)> |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and has a readable bit set |
|
175
|
|
|
|
|
|
|
in the inode mode permissions field (C<$S_IRUSR | $S_IRGRP | $S_IROTH>). |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub is_readable { |
|
180
|
6
|
|
|
6
|
1
|
1126
|
my ( $self, $path ) = @_; |
|
181
|
|
|
|
|
|
|
|
|
182
|
6
|
|
|
|
|
8
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
18
|
|
|
183
|
|
|
|
|
|
|
|
|
184
|
6
|
100
|
|
|
|
232
|
return 0 unless $inode; |
|
185
|
5
|
100
|
|
|
|
72
|
return 0 unless $inode->readable; |
|
186
|
1
|
|
|
|
|
3
|
return 1; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item C<$fs-Eis_writable($path)> |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and has a writable bit set |
|
192
|
|
|
|
|
|
|
in the inode mode permissions field (C<$S_IWUSR | $S_IWGRP | $S_IWOTH>). |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
sub is_writable { |
|
197
|
6
|
|
|
6
|
1
|
1384
|
my ( $self, $path ) = @_; |
|
198
|
|
|
|
|
|
|
|
|
199
|
6
|
|
|
|
|
10
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
15
|
|
|
200
|
|
|
|
|
|
|
|
|
201
|
6
|
100
|
|
|
|
302
|
return 0 unless $inode; |
|
202
|
5
|
100
|
|
|
|
15
|
return 0 unless $inode->writable; |
|
203
|
1
|
|
|
|
|
2
|
return 1; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=item C<$fs-Eis_executable($path)> |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and has an executable bit |
|
209
|
|
|
|
|
|
|
set in the inode mode permissions field (C<$S_IXUSR | $S_IXGRP | $S_IXOTH>). |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
sub is_executable { |
|
214
|
6
|
|
|
6
|
1
|
1185
|
my ( $self, $path ) = @_; |
|
215
|
|
|
|
|
|
|
|
|
216
|
6
|
|
|
|
|
8
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
17
|
|
|
217
|
|
|
|
|
|
|
|
|
218
|
6
|
100
|
|
|
|
310
|
return 0 unless $inode; |
|
219
|
5
|
100
|
|
|
|
16
|
return 0 unless $inode->executable; |
|
220
|
1
|
|
|
|
|
3
|
return 1; |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item C<$fs-Eis_setuid($path)> |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and has a setuid bit |
|
226
|
|
|
|
|
|
|
set in the inode mode permissions field (C<$S_SUID>). |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=cut |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
sub is_setuid { |
|
231
|
6
|
|
|
6
|
1
|
1313
|
my ( $self, $path ) = @_; |
|
232
|
|
|
|
|
|
|
|
|
233
|
6
|
|
|
|
|
7
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
13
|
|
|
234
|
|
|
|
|
|
|
|
|
235
|
6
|
100
|
|
|
|
346
|
return 0 unless $inode; |
|
236
|
5
|
100
|
|
|
|
13
|
return 0 unless $inode->setuid; |
|
237
|
1
|
|
|
|
|
3
|
return 1; |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=item C<$fs-Eis_setgid($path)> |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns true if an inode indicated by C<$path> exists and has a setgid bit |
|
243
|
|
|
|
|
|
|
set in the inode permissions field (C<$S_SGID>). |
|
244
|
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=cut |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
sub is_setgid { |
|
248
|
6
|
|
|
6
|
1
|
1267
|
my ( $self, $path ) = @_; |
|
249
|
|
|
|
|
|
|
|
|
250
|
6
|
|
|
|
|
6
|
my $inode = eval { $self->stat($path) }; |
|
|
6
|
|
|
|
|
14
|
|
|
251
|
|
|
|
|
|
|
|
|
252
|
6
|
100
|
|
|
|
276
|
return 0 unless $inode; |
|
253
|
5
|
100
|
|
|
|
14
|
return 0 unless $inode->setgid; |
|
254
|
1
|
|
|
|
|
3
|
return 1; |
|
255
|
|
|
|
|
|
|
} |
|
256
|
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=back |
|
258
|
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
=cut |
|
260
|
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
262
|
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=over |
|
264
|
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=item L |
|
266
|
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item L |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=back |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
=cut |
|
272
|
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; |
|
274
|
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
__END__ |