POSIX/Snapshot/Inode.pm

filter: Statementstmt 98.4% 65 / 66 Branchbran 95.4% 21 / 22 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 100% 12 / 12 Podpod 33.3% 1 / 3 totaltotal 94.9% 112 / 118 CC 16 SCAR 12.8
CC
16
Cov
97%
from_inode
6.0
open
5.0
_copy_dir
4.0
CRAP 3.6
« POSIX/VFS.pm ↑ Summary POSIX/IO.pm »
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::Snapshot::Inode;
9  
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 ▶use Filesys::POSIX::Bits;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Filesys::POSIX::Mem::Inode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Filesys::POSIX::Mem::Directory ();
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Filesys::POSIX::Mem::Bucket ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Filesys::POSIX::Error qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 our @ISA = qw(Filesys::POSIX::Mem::Inode);
21  
22 46 ▶sub from_inode {
Subroutine from_inode: called CC=6 SCAR=17.9
Pod undocumented
23 46 my ( $class, $inode, %opts ) = @_;
24  
25 46 my $new_inode = bless {
26 'inode' => $inode,
27 'copied' => 0
28 }, $class;
29  
30 46 my @ATTRIBUTES = qw(
31 size atime mtime ctime uid gid mode dev rdev parent
32 );
33  
34 46 @{$new_inode}{@ATTRIBUTES} = @{$inode}{@ATTRIBUTES};
35  
36 #
37 # Overwrite any values within the current inode with ones optionally passed
38 # in %opts.
39 #
40 46 foreach my $attribute (@ATTRIBUTES) {
41 $new_inode->{$attribute} = $opts{$attribute}
42 460 ▶ if exists $opts{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts{$attribute} 89 371 460
43 }
44  
45 #
46 # Copy the symlink destination from the given inode provided, if
47 # present.
48 #
49 46 ▶ if ( $inode->link ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inode->link) 1 45 46
50 1 $new_inode->{'dest'} = $inode->readlink;
51 }
52  
53 #
54 # If it was specified at mount time that we should snapshot directory
55 # listings immediately, then do so.
56 #
57 46 ▶ if ( $inode->dir && $opts{'dev'}->{'flags'}->{'immediate_dir_copy'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inode->dir and $opts{"dev"}{"flags"}{"immediate_dir_copy"}) 15 31 46
Condition100%3/3
$inode->dir and $opts{"dev"}{"flags"}{"immediate_dir_copy"}
!ll&&!rl&&r
161515
MC/DC100%2/2
$inode->dir and $opts{"dev"}{"flags"}{"immediate_dir_copy"}
$inode->dir $opts{"dev"}{"flags"}{"immediate_dir_copy"}
Truth table100%3/3
A and B
A= $inode->dirB= $opts{"dev"}{"flags"}{"immediate_dir_copy"}
ABresult
0X0
100
111
58 15 $new_inode->{'directory'} = $new_inode->_copy_dir( $inode->directory );
59 }
60  
61 46 return $new_inode;
62 }
63  
64 17 ▶sub _copy_dir {
Subroutine _copy_dir: called CC=4 SCAR=13.9
65 17 my ( $self, $directory ) = @_;
66  
67 17 my $new_directory = Filesys::POSIX::Mem::Directory->new;
68  
69 17 $directory->open;
70  
71 17 ▶ while ( defined( my $item = $directory->read ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $item = $directory->read)) 77 17 94
72 77 ▶ next if $item eq '.' || $item eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $item eq "." or $item eq ".." 34 43 77
Condition100%3/3
$item eq "." or $item eq ".."
l!l&&r!l&&!r
171743
MC/DC100%2/2
$item eq "." or $item eq ".."
$item eq "." $item eq ".."
Truth table100%3/3
A or B
A= $item eq "."B= $item eq ".."
ABresult
1X1
011
000
73  
74 43 my $inode = $directory->get($item);
75  
76 $new_directory->set(
77 $item,
78 __PACKAGE__->from_inode(
79 $inode,
80 'parent' => $self,
81 43 'dev' => $self->{'dev'}
82 )
83 );
84 }
85  
86 17 $directory->close;
87  
88 17 return $new_directory;
89 }
90  
91 1 ▶sub _copy_file {
Subroutine _copy_file: called CC=2 SCAR=7.1
92 1 my ($self) = @_;
93  
94 1 my $dev_flags = $self->{'dev'}->{'flags'};
95 1 my $inode_file = $self->{'inode'}->open($O_RDONLY);
96  
97 my $bucket = Filesys::POSIX::Mem::Bucket->new(
98 'inode' => $self,
99 'max' => $dev_flags->{'bucket_max'},
100 1 'dir' => $dev_flags->{'bucket_dir'}
101 );
102  
103 1 ▶ while ( my $len = $inode_file->read( my $buf, 4096 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $len = $inode_file->read(my $buf, 4096)) 0 1 1
104 0 $bucket->write( $buf, $len );
105 }
106  
107 1 $inode_file->close;
108 1 $bucket->close;
109  
110 1 return $bucket;
111 }
112  
113 10 ▶sub directory {
Subroutine directory: called CC=3 SCAR=11.0
Pod documented
114 10 my ($self) = @_;
115  
116 10 ▶ throw &Errno::ENOTDIR unless $self->dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->dir 1 9 10
117  
118 9 ▶ unless ( $self->{'directory'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"directory"}) 2 7 9
119 2 $self->{'directory'} = $self->_copy_dir( $self->{'inode'}->directory );
120 }
121  
122 9 return $self->{'directory'};
123 }
124  
125 4 ▶sub open {
Subroutine open: called CC=5 SCAR=16.1
Pod undocumented
126 4 my ( $self, $flags ) = @_;
127  
128 4 ▶ unless ( $self->{'bucket'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"bucket"}) 2 2 4
129 2 ▶ if ( $self->file && $flags & ( $O_WRONLY | $O_RDWR ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->file and $flags & ($Filesys::POSIX::Snapshot::Inode::O_WRONLY | $Filesys::POSIX::Snapshot::Inode::O_RDWR)) 1 1 2
Condition66%2/3
$self->file and $flags & ($Filesys::POSIX::Snapshot::Inode::O_WRONLY | $Filesys::POSIX::Snapshot::Inode::O_RDWR)
!ll&&!rl&&r
011
MC/DC50%1/2
$self->file and $flags & ($Filesys::POSIX::Snapshot::Inode::O_WRONLY | $Filesys::POSIX::Snapshot::Inode::O_RDWR)
$self->file $flags & ($Filesys::POSIX::Snapshot::Inode::O_WRONLY | $Filesys::POSIX::Snapshot::Inode::O_RDWR)
Truth table66%2/3
A and B
A= $self->fileB= $flags & ($Filesys::POSIX::Snapshot::Inode::O_WRONLY | $Filesys::POSIX::Snapshot::Inode::O_RDWR)
ABresult
0X0
100
111
130 1 $self->{'bucket'} = $self->_copy_file;
131 }
132 }
133  
134 4 ▶ if ( $self->{'bucket'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bucket"}) 3 1 4
135 3 return $self->{'bucket'}->open($flags);
136 }
137  
138 1 return $self->{'inode'}->open($flags);
139 }
140  
141 1 1;
« POSIX/VFS.pm ↑ Summary POSIX/IO.pm »