• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ferki / Rex / 15240232617

28 Feb 2025 09:08AM UTC coverage: 50.961% (+10.2%) from 40.73%
15240232617

push

github

ferki
Use placeholders for template hints

10072 of 19764 relevant lines covered (50.96%)

101.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

17.86
/lib/Rex/Virtualization/VBox/share_folder.pm
1
#
2
# (c) Jan Gehring <jan.gehring@gmail.com>
3
#
4

5
package Rex::Virtualization::VBox::share_folder;
6

7
use v5.12.5;
1✔
8
use warnings;
1✔
9

10
our $VERSION = '9999.99.99_99'; # VERSION
11

12
use Rex::Logger;
1✔
13
use Rex::Helper::Run;
1✔
14
use Rex::Virtualization::VBox::info;
1✔
15

16
#
17
# vm share_folder => "foovm", add => { sharename => "/host/path" };
18
# vm share_folder => "foovm", remove => "sharename";
19
#
20

21
sub execute {
22
  my ( $class, $arg1, $action, $option ) = @_;
×
23

24
  unless ($arg1) {
×
25
    die("You have to define the vm name!");
×
26
  }
27

28
  my $dom = $arg1;
×
29

30
  unless ($dom) {
×
31
    die("VM $dom not found.");
×
32
  }
33

34
  if ( $action eq "add" ) {
×
35
  FOLDER: for my $folder ( keys %{$option} ) {
×
36
      my $info = Rex::Virtualization::VBox::info->execute($dom);
×
37
      my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info};
×
38
      for my $k (@keys) {
×
39
        if ( $info->{$k} eq $folder ) {
×
40

41
          # folder already mapped
42
          next FOLDER;
×
43
        }
44
      }
45

46
      my $from_path = $option->{$folder};
×
47
      i_run
×
48
        "VBoxManage sharedfolder add \"$dom\" --name \"$folder\" --automount --hostpath \"$from_path\"";
49
    }
50
  }
51
  else {
52
    if ( $option ne "-all" ) {
×
53
      i_run "VBoxManage sharedfolder remove \"$dom\" --name \"$option\"";
×
54
    }
55
    else {
56
      # if no name is given, remove all redirects
57
      # output: SharedFolderNameMachineMapping1
58
      my $info = Rex::Virtualization::VBox::info->execute($dom);
×
59
      my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info};
×
60

61
      for my $k (@keys) {
×
62
        i_run "VBoxManage sharedfolder delete \"$dom\" --name \"$info->{$k}\"";
×
63
      }
64
    }
65

66
  }
67

68
  if ( $? != 0 ) {
×
69
    die("Error setting folder shares for vm $dom");
×
70
  }
71

72
}
73

74
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc