Class: VagrantPlugins::SyncedFolderSSHFS::HostPathFixCommon

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Action::Builtin::MixinSyncedFolders
Defined in:
lib/vagrant-sshfs/action_hostpath_fixup.rb

Overview

Class that contains common function that are called by both HostPathFix and HostPathUnfix classes.

Instance Method Summary collapse

Constructor Details

#initializeHostPathFixCommon

Returns a new instance of HostPathFixCommon.



14
15
16
# File 'lib/vagrant-sshfs/action_hostpath_fixup.rb', line 14

def initialize()
  @logger = Log4r::Logger.new("vagrant::synced_folders::sshfs")
end

Instance Method Details

#fix(data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-sshfs/action_hostpath_fixup.rb', line 18

def fix(data)
  # If this is an arbitrary host mount we need to set the hostpath
  # to something that will pass the config checks that assume the
  # hostpath is coming from the vagrant host and not from an arbitrary
  # host. Save off the original hostpath and then set the hostpath to 
  # "." to pass the checks.
  if data[:ssh_host]
    data[:hostpath_orig] = data[:hostpath]
    data[:hostpath] = "."
  end
end

#loop_and_fix_unfix(env, fix) ⇒ Object

Loop through synced folder entries and either fix or unfix based on the fix arg



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
# File 'lib/vagrant-sshfs/action_hostpath_fixup.rb', line 43

def loop_and_fix_unfix(env, fix)

  opts = {
    cached: !!env[:synced_folders_cached],
    config: env[:synced_folders_config],
  }

  @logger.debug("SyncedFolders loading from cache: #{opts[:cached]}")
  folders = synced_folders(env[:machine], **opts)

  folders.each do |impl_name, fs|
    next if impl_name != :sshfs
    @logger.debug("Synced Folder Implementation: #{impl_name}")

    fs.each do |id, data|

      # replace data with a copy since we may delete/add new data to the config
      data = data.dup

      if fix
          @logger.debug("fixup host path before:  - #{id}: #{data[:hostpath]} => #{data[:guestpath]}")
          fix(data)
          @logger.debug("fixup host path after:  - #{id}: #{data[:hostpath]} => #{data[:guestpath]}")
      else
          @logger.debug("unfixup host path before:  - #{id}: #{data[:hostpath]} => #{data[:guestpath]}")
          unfix(data)
          @logger.debug("fixup host path after:  - #{id}: #{data[:hostpath]} => #{data[:guestpath]}")
      end

      # Replace the entry in the config with the updated one
      env[:machine].config.vm.synced_folders.delete(id)
      env[:machine].config.vm.synced_folder(
          data[:hostpath],
          data[:guestpath],
          data)
    end
  end
end

#unfix(data) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/vagrant-sshfs/action_hostpath_fixup.rb', line 30

def unfix(data)
  # If this is a reverse mounted folder or an arbitrary host mount
  # then we'll set "hostpath_exact" so they don't try to create a
  # folder on the host in Vagrant::Action::Builtin::SyncedFolders.
  if data[:ssh_host]
    data[:hostpath_exact] = true
    data[:hostpath] = data[:hostpath_orig]
    data.delete(:hostpath_orig)
  end
end