lib/Rex/Commands/Mkfs.pm

filter: Statementstmt 55.8% 24 / 43 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 36.7% 32 / 87 CC 12 SCAR 45.9
CC
12
Cov
34%
mkfs
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 98.9
« lib/Rex/Virtualization/Docker/create.pm ↑ Summary lib/Rex/Resource/firewall.pm »
1  
2 =head1 NAME
3  
4 Rex::Commands::Mkfs - Create filesystems
5  
6 =head1 DESCRIPTION
7  
8 With this module you can create filesystems on existing partitions and logical volumes.
9  
10 =head1 SYNOPSIS
11  
12 use Rex::Commands::Mkfs;
13  
14 =head1 EXPORTED FUNCTIONS
15  
16 =cut
17  
18 package Rex::Commands::Mkfs;
19  
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our $VERSION = '1.16.1'; # VERSION
24  
25 1 require Rex::Exporter;
26 1 ▶use base qw(Rex::Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 @EXPORT = qw(mkfs);
30  
31 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 =head2 mkfs($devname, %option)
36  
37 Create a filesystem on device $devname.
38  
39 mkfs "sda1",
40 fstype => "ext2",
41 label => "mydisk";
42  
43 mkfs "sda2",
44 fstype => "swap";
45  
46 =cut
47  
48 0 ▶sub mkfs {
Subroutine mkfs: not called CC=12 SCAR=50.5
Pod documented
49 0 my ( $devname, %option ) = @_;
50  
51 0 ▶ if ( $devname !~ m/^\// ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($devname =~ m[^/]u) 0 0 0
52 0 $devname = "/dev/$devname";
53 }
54  
55 0 my $add_opts = "";
56  
57 0 ▶ unless ( exists $option{fstype} && defined $option{fstype} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $option{"fstype"} and defined $option{"fstype"}) 0 0 0
Condition0%0/3
exists $option{"fstype"} and defined $option{"fstype"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $option{"fstype"} and defined $option{"fstype"}
exists $option{"fstype"} defined $option{"fstype"}
Truth table0%0/3
A and B
A= exists $option{"fstype"}B= defined $option{"fstype"}
ABresult
0X0
100
111
58 0 croak("Missing or undefined fstype.");
59 }
60  
61 0 ▶ if ( grep { $option{fstype} eq $_ } ( "non-fs", "none", "" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$option{"fstype"} eq $_;} "non-fs", "none", "") 0 0 0
62 0 Rex::Logger::debug("Skip creating a filesystem of type '$option{fstype}'");
63 0 return;
64 }
65  
66 0 ▶ if ( ( exists $option{label} && $option{label} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $option{"label"} and $option{"label"} or exists $option{"lable"} and $option{"lable"}) 0 0 0
Condition0%0/9
exists $option{"label"} and $option{"label"} or exists $option{"lable"} and $option{"lable"}
l!l&&r!l&&!r
000
exists $option{"label"} and $option{"label"}
!ll&&!rl&&r
000
exists $option{"lable"} and $option{"lable"}
!ll&&!rl&&r
000
MC/DC0%0/4
exists $option{"label"} and $option{"label"} or exists $option{"lable"} and $option{"lable"}
exists $option{"label"} $option{"label"} exists $option{"lable"} $option{"lable"}
Truth table0%0/7
A and B or C and D
A= exists $option{"label"}B= $option{"label"}C= exists $option{"lable"}D= $option{"lable"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
67 || ( exists $option{lable} && $option{lable} ) )
68 {
69 0 ▶ my $label = $option{label} || $option{lable};
Condition0%0/3
$option{'label'} || $option{'lable'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$option{'label'} || $option{'lable'}
$option{'label'} $option{'lable'}
Truth table0%0/3
A || B
A= $option{'label'}B= $option{'lable'}
ABresult
1X1
011
000
70 0 $add_opts .= " -L $label ";
71 }
72  
73 0 ▶ if ( $option{fstype} eq "swap" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($option{'fstype'} eq 'swap') { } 0 0 0
elsif (can_run("mkfs.$option{'fstype'}")) { } 0 0 0
74 0 Rex::Logger::info("Creating swap space on $devname");
75 0 i_run "mkswap $add_opts -f $devname";
76 }
77 elsif ( can_run("mkfs.$option{fstype}") ) {
78 0 Rex::Logger::info("Creating filesystem $option{fstype} on $devname");
79  
80 0 i_run "mkfs.$option{fstype} $add_opts $devname";
81 }
82  
83 0 return;
84 }
85  
86 1 1;
« lib/Rex/Virtualization/Docker/create.pm ↑ Summary lib/Rex/Resource/firewall.pm »