core: Introduce a synced folder plugin for vagrant 1.4+
This commit is contained in:
parent
a0acc571b2
commit
8f1b54395e
3 changed files with 48 additions and 0 deletions
|
@ -5,6 +5,10 @@ module Vagrant
|
|||
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.3.0')
|
||||
end
|
||||
|
||||
def vagrant_1_4_or_later?
|
||||
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.4.0')
|
||||
end
|
||||
|
||||
def vagrant_1_5_or_later?
|
||||
Gem::Version.new(Vagrant::VERSION) >= Gem::Version.new('1.5.0')
|
||||
end
|
||||
|
|
|
@ -23,6 +23,13 @@ module Vagrant
|
|||
require File.expand_path("../config", __FILE__)
|
||||
Config
|
||||
end
|
||||
|
||||
if Vagrant::Backports.vagrant_1_4_or_later?
|
||||
synced_folder(:lxc) do
|
||||
require File.expand_path("../synced_folder", __FILE__)
|
||||
SyncedFolder
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
37
lib/vagrant-lxc/synced_folder.rb
Normal file
37
lib/vagrant-lxc/synced_folder.rb
Normal file
|
@ -0,0 +1,37 @@
|
|||
module Vagrant
|
||||
module LXC
|
||||
class SyncedFolder < Vagrant.plugin("2", :synced_folder)
|
||||
def usable?(machine)
|
||||
# These synced folders only work if the provider is LXC
|
||||
machine.provider_name == :lxc
|
||||
end
|
||||
|
||||
def prepare(machine, folders, _opts)
|
||||
machine.ui.output(I18n.t("vagrant.actions.vm.share_folders.mounting"))
|
||||
|
||||
folders.each do |id, data|
|
||||
host_path = Pathname.new(File.expand_path(data[:hostpath], machine.env.root_path))
|
||||
guest_path = data[:guestpath]
|
||||
|
||||
if !host_path.directory? && data[:create]
|
||||
# Host path doesn't exist, so let's create it.
|
||||
@logger.debug("Host path doesn't exist, creating: #{host_path}")
|
||||
|
||||
begin
|
||||
host_path.mkpath
|
||||
rescue Errno::EACCES
|
||||
raise Vagrant::Errors::SharedFolderCreateFailed,
|
||||
:path => hostpath.to_s
|
||||
end
|
||||
end
|
||||
|
||||
machine.provider.driver.share_folder(host_path, guest_path)
|
||||
# Guest path specified, so mount the folder to specified point
|
||||
machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
||||
guestpath: data[:guestpath],
|
||||
hostpath: data[:hostpath]))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue