POSIX/Real/Inode.pm

filter: Statementstmt 68.0% 64 / 94 Branchbran 42.0% 21 / 50 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 73.6% 14 / 19 Podpod 10.0% 1 / 10 totaltotal 57.3% 102 / 178 CC 27 SCAR 19.4
CC
27
Cov
59%
chown
12.0
chmod
12.0
readlink
12.0
CRAP 7.0
« POSIX/ReducedPrivileges.pm ↑ Summary POSIX/Userland/Tar/Header.pm »
1 # Copyright (c) 2016, 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::Real::Inode;
9  
10 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 13 ▶use Filesys::POSIX::Bits;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use Filesys::POSIX::Bits::System;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use Filesys::POSIX::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Filesys::POSIX::Mem::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 13 ▶use Filesys::POSIX::IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18 13 ▶use Filesys::POSIX::Error qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 13 ▶use Fcntl qw(:DEFAULT :mode);
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 13 our @ISA = qw(Filesys::POSIX::Inode);
23  
24 39 ▶sub new {
Subroutine new: called CC=5 SCAR=17.0
Pod undocumented
25 39 my ( $class, $path, %opts ) = @_;
26  
27 39 my $sticky = 0;
28  
29 #
30 # Allow the sticky flag to be set for every inode belonging to a
31 # Filesys::POSIX::Real filesystem, with usage of a special mount flag.
32 # However, allow this flag to be overridden on a per-inode basis, which
33 # happens with each call from Filesys::POSIX::Extensions->map and the like.
34 #
35 39 ▶ if ( defined $opts{'dev'}->{'sticky'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"dev"}{"sticky"}) 0 39 39
36 0 ▶ $sticky = $opts{'dev'}->{'sticky'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'dev'}{'sticky'} ? : 0 0 0
37 }
38  
39 39 ▶ if ( defined $opts{'sticky'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"sticky"}) 11 28 39
40 11 ▶ $sticky = $opts{'sticky'} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'sticky'} ? : 7 4 11
41 }
42  
43 return bless {
44 'path' => $path,
45 'dev' => $opts{'dev'},
46 39 'parent' => $opts{'parent'},
47 'sticky' => $sticky,
48 'dirty' => 0
49 }, $class;
50 }
51  
52 39 ▶sub from_disk {
Subroutine from_disk: called CC=4 SCAR=13.9
Pod undocumented
53 39 my ( $class, $path, %opts ) = @_;
54 39 ▶ my @st = $opts{'st_info'} ? @{ $opts{'st_info'} } : lstat $path or Carp::confess("$!");
Branch: 2 branches
BranchTrueFalseTotal
my(@st) = $opts{"st_info"} ? @{$opts{"st_info"};} : lstat $path or Carp::confess("$!") 39 0 39
$opts{'st_info'} ? : 18 21 39
55  
56 39 my $inode = $class->new( $path, %opts )->update(@st);
57  
58 39 ▶ if ( S_IFMT( $st[2] ) == S_IFDIR ) {
Branch: 1 branch
BranchTrueFalseTotal
if (S_IFMT($st[2]) == 16384) 20 19 39
59 20 $inode->{'directory'} = Filesys::POSIX::Real::Directory->new( $path, $inode );
60 }
61  
62 39 return $inode;
63 }
64  
65 4 ▶sub child {
Subroutine child: called CC=9 SCAR=24.2
Pod undocumented
66 4 my ( $self, $name, $mode ) = @_;
67 4 my $directory = $self->directory;
68  
69 4 ▶ throw &Errno::EINVAL if $name =~ /\//;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ m[/] 0 4 4
70 4 ▶ throw &Errno::EEXIST if $directory->exists($name);
Branch: 1 branch
BranchTrueFalseTotal
if $directory->exists($name) 0 4 4
71  
72 4 my $path = "$self->{'path'}/$name";
73  
74 my %data = (
75 'dev' => $self->{'dev'},
76 4 'sticky' => $self->{'sticky'},
77 'parent' => $directory->get('.')
78 );
79  
80 4 ▶ if ( ( $mode & $S_IFMT ) == $S_IFREG ) {
Branch: 2 branches
BranchTrueFalseTotal
if (($mode & $Filesys::POSIX::Real::Inode::S_IFMT) == $Filesys::POSIX::Real::Inode::S_IFREG) { } 2 2 4
elsif (($mode & $Filesys::POSIX::Real::Inode::S_IFMT) == $Filesys::POSIX::Real::Inode::S_IFDIR) { } 2 0 2
81 2 ▶ sysopen(
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $path, 193, Filesys::POSIX::Bits::System::convertModeToSystem($mode) or Carp::confess("$!") 2 0 2
82 my $fh, $path,
83 O_CREAT | O_EXCL | O_WRONLY,
84 Filesys::POSIX::Bits::System::convertModeToSystem($mode)
85 ) or Carp::confess("$!");
86 2 close($fh);
87 }
88 elsif ( ( $mode & $S_IFMT ) == $S_IFDIR ) {
89 2 ▶ mkdir( $path, $mode ) or Carp::confess("$!");
Branch: 1 branch
BranchTrueFalseTotal
mkdir $path, $mode or Carp::confess("$!") 2 0 2
90 }
91  
92 4 my $inode;
93  
94 4 ▶ if ( ( $mode & $S_IFMT ) == $S_IFLNK ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($mode & $Filesys::POSIX::Real::Inode::S_IFMT) == $Filesys::POSIX::Real::Inode::S_IFLNK) { } 0 4 4
95 0 ▶ throw &Errno::EPERM unless $self->{'sticky'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sticky"} 0 0 0
96  
97 0 $inode = Filesys::POSIX::Mem::Inode->new( %data, 'mode' => $mode );
98 }
99 else {
100 4 my $class = ref $self;
101 4 $inode = $class->from_disk( $path, %data );
102 }
103  
104 4 return $directory->set( $name, $inode );
105 }
106  
107 0 ▶sub taint {
Subroutine taint: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my ($self) = @_;
109  
110 0 $self->{'dirty'} = 1;
111  
112 0 return $self;
113 }
114  
115 46 ▶sub update {
Subroutine update: called CC=3 SCAR=12.3
Pod documented
116 46 my ( $self, @st ) = @_;
117  
118 46 ▶ if ( $self->{'sticky'} && $self->{'dirty'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'sticky'} and $self->{'dirty'}) { } 0 46 46
Condition66%2/3
$self->{"sticky"} and $self->{"dirty"}
!ll&&!rl&&r
3970
MC/DC0%0/2
$self->{"sticky"} and $self->{"dirty"}
$self->{"sticky"} $self->{"dirty"}
Truth table66%2/3
A and B
A= $self->{"sticky"}B= $self->{"dirty"}
ABresult
0X0
100
111
119 0 @{$self}{qw(rdev size atime mtime ctime)} = @st[ 6 .. 10 ];
120 }
121 else {
122 46 $self->SUPER::update(@st);
123 }
124  
125 46 return $self;
126 }
127  
128 7 ▶sub open {
Subroutine open: called CC=2 SCAR=6.9
Pod undocumented
129 7 my ( $self, $flags ) = @_;
130  
131 sysopen(
132 7 ▶ my $fh, $self->{'path'},
Branch: 1 branch
BranchTrueFalseTotal
sysopen my $fh, $self->{"path"}, Filesys::POSIX::Bits::System::convertFlagsToSystem($flags) or Carp::confess("$!") 5 2 7
133 Filesys::POSIX::Bits::System::convertFlagsToSystem($flags)
134 ) or Carp::confess("$!");
135  
136 5 return Filesys::POSIX::IO::Handle->new($fh);
137 }
138  
139 0 ▶sub chown {
Subroutine chown: not called CC=3 SCAR=24.8
Pod undocumented
140 0 my ( $self, $uid, $gid ) = @_;
141  
142 0 ▶ unless ( $self->{'sticky'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sticky"}) 0 0 0
143 0 ▶ CORE::chown( $uid, $gid, $self->{'path'} ) or Carp::confess("$!");
Branch: 1 branch
BranchTrueFalseTotal
CORE::chown $uid, $gid, $self->{"path"} or Carp::confess("$!") 0 0 0
144 }
145  
146 0 @{$self}{qw(uid gid)} = ( $uid, $gid );
147  
148 0 return $self->taint;
149 }
150  
151 0 ▶sub chmod {
Subroutine chmod: not called CC=3 SCAR=24.8
Pod undocumented
152 0 my ( $self, $mode ) = @_;
153 0 my $format = $self->{'mode'} & $S_IFMT;
154 0 my $perm = $mode & ( $S_IPERM | $S_IPROT );
155  
156 0 ▶ unless ( $self->{'sticky'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sticky"}) 0 0 0
157 0 ▶ CORE::chmod( $perm, $self->{'path'} ) or Carp::confess("$!");
Branch: 1 branch
BranchTrueFalseTotal
CORE::chmod $perm, $self->{"path"} or Carp::confess("$!") 0 0 0
158 }
159  
160 0 $self->{'mode'} = $format | $perm;
161  
162 0 return $self->taint;
163 }
164  
165 0 ▶sub readlink {
Subroutine readlink: not called CC=3 SCAR=24.8
Pod undocumented
166 0 my ($self) = @_;
167  
168 0 ▶ unless ( $self->{'dest'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"dest"}) 0 0 0
169 0 ▶ $self->{'dest'} = CORE::readlink( $self->{'path'} ) or Carp::confess("$!");
Branch: 1 branch
BranchTrueFalseTotal
$self->{"dest"} = CORE::readlink $self->{"path"} or Carp::confess("$!") 0 0 0
170 }
171  
172 0 return $self->{'dest'};
173 }
174  
175 0 ▶sub symlink {
Subroutine symlink: not called CC=3 SCAR=24.8
Pod undocumented
176 0 my ( $self, $dest ) = @_;
177  
178 0 ▶ unless ( $self->{'sticky'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sticky"}) 0 0 0
179 0 ▶ symlink( $dest, $self->{'path'} ) or Carp::confess("$!");
Branch: 1 branch
BranchTrueFalseTotal
CORE::symlink $dest, $self->{"path"} or Carp::confess("$!") 0 0 0
180 }
181  
182 0 $self->{'dest'} = $dest;
183  
184 0 return $self->taint;
185 }
186  
187 13 1;
« POSIX/ReducedPrivileges.pm ↑ Summary POSIX/Userland/Tar/Header.pm »