Class: HashiCorp::VagrantVMwareDesktop::Action::ShareFolders
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::Action::ShareFolders
- Includes:
- Common, Vagrant::Util::ScopedHashOverride
- Defined in:
- lib/vagrant-vmware-desktop/action/share_folders.rb
Overview
This takes the configured synced folders on the VM and shares them into the VMware guest.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ ShareFolders
constructor
A new instance of ShareFolders.
Methods included from Common
Constructor Details
#initialize(app, env) ⇒ ShareFolders
Returns a new instance of ShareFolders.
18 19 20 21 |
# File 'lib/vagrant-vmware-desktop/action/share_folders.rb', line 18 def initialize(app, env) @app = app @logger = Log4r::Logger.new("hashicorp::provider::vmware::shared_folders") end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vagrant-vmware-desktop/action/share_folders.rb', line 23 def call(env) # Move on first so that the machine is powered on @app.call(env) shared_folders = {} env[:machine].config.vm.synced_folders.each do |id, data| data = scoped_hash_override(data, :vmware) # Ignore disabled shared folders if data[:disabled] @logger.info("Disabled shared folder, ignoring: #{id}") next end # Ignore NFS shared folders as well next if data[:nfs] # Use it! shared_folders[id] = data end if shared_folders.empty? @logger.info("No shared folders. Doing nothing.") return end # Verify that the machine can actually support sharing folders # if we can. if env[:machine].guest.capability?(:verify_vmware_hgfs) @logger.info("Verifying HGFS is on the guest...") if !env[:machine].guest.capability(:verify_vmware_hgfs) raise Errors::GuestMissingHGFS end end # Get the SSH info which we'll use later ssh_info = env[:machine].ssh_info # short guestpaths first, so we don't step on ourselves shared_folders = shared_folders.dup.sort_by do |id, data| if data[:guestpath] data[:guestpath].length else # A long enough path to just do this at the end. 10000 end end @logger.info("Preparing shared folders with VMX...") env[:ui].info I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folders") env[:machine].provider.driver.enable_shared_folders shared_folders.each do |id, data| id = id.gsub('/', env[:machine].provider_config.shared_folder_special_char) path = File.(data[:hostpath], env[:root_path]) guestpath = data[:guestpath] env[:ui].info(I18n.t("hashicorp.vagrant_vmware_desktop.sharing_folder_single", hostpath: path, guestpath: guestpath)) env[:machine].provider.driver.share_folder(id, path) # Remove trailing slashes guestpath = guestpath.gsub(/\/+$/, "") # Calculate the owner and group data[:owner] ||= ssh_info[:username] data[:group] ||= ssh_info[:username] # Mount it! env[:machine].guest.capability( :mount_vmware_shared_folder, id, data[:guestpath], data) end end |