lib/Rex/Virtualization/VBox/share_folder.pm

filter: Statementstmt 36.3% 16 / 44 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 33.3% 21 / 63 CC 10 SCAR 43.0
CC
10
Cov
29%
execute
110.0
BEGIN
1.0
BEGIN
1.0
CRAP 73.7
« lib/Rex/Virtualization/VBox/start.pm ↑ Summary lib/Rex/Template/NG.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::VBox::share_folder;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Virtualization::VBox::info;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 #
17 # vm share_folder => "foovm", add => { sharename => "/host/path" };
18 # vm share_folder => "foovm", remove => "sharename";
19 #
20  
21 0 ▶sub execute {
Subroutine execute: not called CC=10 SCAR=47.0
Pod undocumented
22 0 my ( $class, $arg1, $action, $option ) = @_;
23  
24 0 ▶ unless ($arg1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg1) 0 0 0
25 0 die("You have to define the vm name!");
26 }
27  
28 0 my $dom = $arg1;
29  
30 0 ▶ unless ($dom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dom) 0 0 0
31 0 die("VM $dom not found.");
32 }
33  
34 0 ▶ if ( $action eq "add" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'add') { } 0 0 0
35 0 FOLDER: for my $folder ( keys %{$option} ) {
36 0 my $info = Rex::Virtualization::VBox::info->execute($dom);
37 0 my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info};
38 0 for my $k (@keys) {
39 0 ▶ if ( $info->{$k} eq $folder ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{$k} eq $folder) 0 0 0
40  
41 # folder already mapped
42 0 next FOLDER;
43 }
44 }
45  
46 0 my $from_path = $option->{$folder};
47 0 i_run
48 "VBoxManage sharedfolder add \"$dom\" --name \"$folder\" --automount --hostpath \"$from_path\"";
49 }
50 }
51 else {
52 0 ▶ if ( $option ne "-all" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option ne '-all') { } 0 0 0
53 0 i_run "VBoxManage sharedfolder remove \"$dom\" --name \"$option\"";
54 }
55 else {
56 # if no name is given, remove all redirects
57 # output: SharedFolderNameMachineMapping1
58 0 my $info = Rex::Virtualization::VBox::info->execute($dom);
59 0 my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info};
60  
61 0 for my $k (@keys) {
62 0 i_run "VBoxManage sharedfolder delete \"$dom\" --name \"$info->{$k}\"";
63 }
64 }
65  
66 }
67  
68 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
69 0 die("Error setting folder shares for vm $dom");
70 }
71  
72 }
73  
74 1 1;
« lib/Rex/Virtualization/VBox/start.pm ↑ Summary lib/Rex/Template/NG.pm »