Class: VagrantPlugins::Bindfs::Action::Bind

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-bindfs/bind.rb

Constant Summary collapse

@@options =

Options

{
  :owner                => 'vagrant',
  :group                => 'vagrant',
  :perms                => 'u=rwX:g=rD:o=rD',
  :mirror               => nil,
  :'mirror-only'        => nil,
  :'create-for-user'    => nil,
  :'create-for-group'   => nil,
  :'create-with-perms'  => nil,
}
@@shorthands =

Shorthands

{
  :o                    => nil,
}
@@flags =

Flags

{
  :'no-allow-other'     => false,
  :'create-as-user'     => false,
  :'create-as-mounter'  => false,
  :'chown-normal'       => false,
  :'chown-ignore'       => false,
  :'chown-deny'         => false,
  :'chgrp-normal'       => false,
  :'chgrp-ignore'       => false,
  :'chgrp-deny'         => false,
  :'chmod-normal'       => false,
  :'chmod-ignore'       => false,
  :'chmod-deny'         => false,
  :'chmod-allow-x'      => false,
  :'xattr-none'         => false,
  :'xattr-ro'           => false,
  :'xattr-rw'           => false,
  :'ctime-from-mtime'   => false,
}

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Bind

Returns a new instance of Bind.



44
45
46
47
# File 'lib/vagrant-bindfs/bind.rb', line 44

def initialize(app, env)
  @app = app
  @env = env
end

Instance Method Details

#bind_foldersObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/vagrant-bindfs/bind.rb', line 84

def bind_folders
  @env[:ui].info I18n.t("vagrant.config.bindfs.status.binding_all")

  binded_folders.each do |id, opts|
    source, dest, args = normalize_options opts
    bind_command = "sudo bindfs#{args} #{source} #{dest}"
  
    unless @machine.communicate.test("test -d #{source}")
      @env[:ui].error(I18n.t('vagrant.config.bindfs.errors.source_path_not_exist', :path => source))
      next
    end

    if @machine.communicate.test("mount | grep bindfs | grep ' #{dest} '")
      @env[:ui].info(I18n.t('vagrant.config.bindfs.already_mounted', :dest => dest))
      next
    end

    @env[:ui].info I18n.t("vagrant.config.bindfs.status.binding_entry", :source => source, :dest => dest)

    @machine.communicate.sudo("mkdir -p #{dest}")
    @machine.communicate.sudo(bind_command, :error_class => Error, :error_key => :binding_failed)
  end
end

#binded_foldersObject



61
62
63
# File 'lib/vagrant-bindfs/bind.rb', line 61

def binded_folders
  @machine.config.bindfs.bind_folders
end

#call(env) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-bindfs/bind.rb', line 49

def call(env)
  @app.call(env)
  @env = env
  
  @machine = env[:machine]

  unless binded_folders.empty?
    handle_bindfs_installation
    bind_folders
  end
end

#default_optionsObject



65
66
67
# File 'lib/vagrant-bindfs/bind.rb', line 65

def default_options
  @@options.merge(@@shorthands).merge(@@flags).merge(@machine.config.bindfs.default_options)
end

#handle_bindfs_installationObject



108
109
110
111
112
113
114
115
116
# File 'lib/vagrant-bindfs/bind.rb', line 108

def handle_bindfs_installation
  if !@machine.guest.capability(:bindfs_installed)
    @env[:ui].warn(I18n.t('vagrant.config.bindfs.not_installed'))

    if !@machine.guest.capability(:bindfs_install)
      raise Vagrant::Bindfs::Error, :cannot_install
    end
  end
end

#normalize_options(opts) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant-bindfs/bind.rb', line 69

def normalize_options opts
  source  = opts.delete(:source_path)
  dest    = opts.delete(:dest_path)
  opts    = default_options.merge(opts)

  args = []
  opts.each do |key, value|
    args << "--#{key.to_s}"          if @@flags.key?(key) and !!value 
    args << "--#{key.to_s}=#{value}" if @@options.key?(key) and !value.nil?
    args << "-#{key.to_s} #{value}"  if @@shorthands.key?(key) and !value.nil?
  end
  
  [ source, dest, " #{args.join(" ")}" ]
end