| 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::Inode; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 27 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 27 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 27 | ▶ | use Filesys::POSIX::Bits; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 27 | ▶ | use Filesys::POSIX::Error qw(throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | Filesys::POSIX::Inode - Base class for filesystem inode objects | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | Provides a base class for filesystem-type dependent inode objects. This class | ||||||||||||||||||||||||||||
| 23 | offers a number of methods used to help determine the nature of the inode by | ||||||||||||||||||||||||||||
| 24 | analyzing its attributes. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | =over | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | =item C<$inode-E<gt>dir> | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | Returns true if the current inode refers to a directory. | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 1769 | ▶ | sub dir { | ||||||||||||||||||||||||||
|
Subroutine
dir: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 1769 | ( shift->{'mode'} & $S_IFMT ) == $S_IFDIR; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =item C<$inode-E<gt>link> | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | Returns true if the current inode is a symlink. | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =cut | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 851 | ▶ | sub link { | ||||||||||||||||||||||||||
|
Subroutine
link: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 851 | ( shift->{'mode'} & $S_IFMT ) == $S_IFLNK; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =item C<$inode-E<gt>file> | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Returns true if the current inode is a regular file. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 167 | ▶ | sub file { | ||||||||||||||||||||||||||
|
Subroutine
file: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 167 | ( shift->{'mode'} & $S_IFMT ) == $S_IFREG; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item C<$inode-E<gt>char> | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Returns true if the current inode is a character device. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 93 | ▶ | sub char { | ||||||||||||||||||||||||||
|
Subroutine
char: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 93 | ( shift->{'mode'} & $S_IFMT ) == $S_IFCHR; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =item C<$inode-E<gt>block> | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Returns true if the current inode is a block device. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 91 | ▶ | sub block { | ||||||||||||||||||||||||||
|
Subroutine
block: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 91 | ( shift->{'mode'} & $S_IFMT ) == $S_IFBLK; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =item C<$inode-E<gt>fifo> | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Returns true if the current inode is a FIFO. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 6 | ▶ | sub fifo { | ||||||||||||||||||||||||||
|
Subroutine
fifo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 6 | ( shift->{'mode'} & $S_IFMT ) == $S_IFIFO; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =item C<$inode-E<gt>sock> | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Returns true if the current inode refers to a socket. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 76 | ▶ | sub sock { | ||||||||||||||||||||||||||
|
Subroutine
sock: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 76 | ( shift->{'mode'} & $S_IFMT ) == $S_IFSOCK; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | =item C<$inode-E<gt>major> | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | If the current inode is a block or character device, return the major number. | ||||||||||||||||||||||||||||
| 101 | Otherwise, an EINVAL is thrown. | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | sub major { | ||||||||||||||||||||||||||
|
Subroutine
major: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 3 | ▶ | throw &Errno::EINVAL unless $self->char || $self->block; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->char or $self->block
MC/DC100%2/2
$self->char or $self->block
$self->char
$self->block
Truth table100%3/3
A or B
A= $self->charB= $self->block
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 2 | return ( $self->{'rdev'} & 0xffff0000 ) >> 16; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =item C<$inode-E<gt>minor> | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | If the current inode is a block or character device, return the minor number. | ||||||||||||||||||||||||||||
| 116 | Otherwise, an EINVAL is thrown. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | sub minor { | ||||||||||||||||||||||||||
|
Subroutine
minor: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 3 | ▶ | throw &Errno::EINVAL unless $self->char || $self->block; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->char or $self->block
MC/DC100%2/2
$self->char or $self->block
$self->char
$self->block
Truth table100%3/3
A or B
A= $self->charB= $self->block
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 2 | return $self->{'rdev'} & 0x0000ffff; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =item C<$inode-E<gt>perms> | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | Returns the permissions bitfield value of the current inode's mode attribute. | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | =cut | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 6 | ▶ | sub perms { | ||||||||||||||||||||||||||
|
Subroutine
perms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 135 | 6 | shift->{'mode'} & $S_IPERM; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =item C<$inode-E<gt>readable> | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | Returns true if the inode is readable by anyone. | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 7 | ▶ | sub readable { | ||||||||||||||||||||||||||
|
Subroutine
readable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 7 | ( shift->{'mode'} & $S_IR ) != 0; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =item C<$inode-E<gt>writable> | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | Returns true if the inode is writable by anyone. | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 7 | ▶ | sub writable { | ||||||||||||||||||||||||||
|
Subroutine
writable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 155 | 7 | ( shift->{'mode'} & $S_IW ) != 0; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =item C<$inode-E<gt>executable> | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | Returns true if the inode is executable by anyone. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 7 | ▶ | sub executable { | ||||||||||||||||||||||||||
|
Subroutine
executable: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 7 | ( shift->{'mode'} & $S_IX ) != 0; | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item C<$inode-E<gt>setuid> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | Returns true if the inode has a setuid bit set. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | =cut | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 7 | ▶ | sub setuid { | ||||||||||||||||||||||||||
|
Subroutine
setuid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 175 | 7 | ( shift->{'mode'} & $S_ISUID ) != 0; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | =item C<$inode-E<gt>setgid> | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | Returns true if the inode has a setgid bit set. | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 7 | ▶ | sub setgid { | ||||||||||||||||||||||||||
|
Subroutine
setgid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 185 | 7 | ( shift->{'mode'} & $S_ISGID ) != 0; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | =item C<$inode-E<gt>update(@st)> | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | Updates the current inode object with a list of values as returned by | ||||||||||||||||||||||||||||
| 191 | L<stat()|perlfunc/stat>. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 46 | ▶ | sub update { | ||||||||||||||||||||||||||
|
Subroutine
update: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 196 | 46 | my ( $self, @st ) = @_; | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 46 | @{$self}{qw(size atime mtime ctime uid gid mode rdev)} = | |||||||||||||||||||||||||||
| 199 | ( @st[ 7 .. 10 ], @st[ 4 .. 5 ], $st[2], $st[6] ); | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 46 | return $self; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =item C<$inode-E<gt>directory> | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | If the current inode is a directory, return the directory object held by it. | ||||||||||||||||||||||||||||
| 207 | Otherwise, an ENOTDIR is thrown. | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | =cut | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 1290 | ▶ | sub directory { | ||||||||||||||||||||||||||
|
Subroutine
directory: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 1290 | my ($self) = @_; | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 1290 | ▶ | throw &Errno::ENOTDIR unless $self->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 1287 | return $self->{'directory'}; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =item C<$inode-E<gt>empty> | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | Uses the above C<$inode-E<gt>directory()> call to obtain the directory for the | ||||||||||||||||||||||||||||
| 222 | current inode, and returns the result of C<$directory-E<gt>empty()>. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =cut | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 5 | ▶ | sub empty { | ||||||||||||||||||||||||||
|
Subroutine
empty: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 5 | my ($self) = @_; | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 5 | return $self->directory->empty; | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | =back | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | =cut | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 27 | 1; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | __END__ | ||||||||||||||||||||||||||||