2013-03-04 01:42:18 +00:00
|
|
|
module Vagrant
|
|
|
|
module LXC
|
|
|
|
module Action
|
2013-04-02 00:05:19 +00:00
|
|
|
class ShareFolders
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
2013-03-04 01:42:18 +00:00
|
|
|
def call(env)
|
|
|
|
@env = env
|
|
|
|
prepare_folders
|
2013-04-06 01:08:02 +00:00
|
|
|
add_override_configs
|
2013-03-04 01:42:18 +00:00
|
|
|
@app.call env
|
|
|
|
end
|
|
|
|
|
|
|
|
# This method returns an actual list of VirtualBox shared
|
|
|
|
# folders to create and their proper path.
|
|
|
|
def shared_folders
|
|
|
|
{}.tap do |result|
|
|
|
|
@env[:machine].config.vm.synced_folders.each do |id, data|
|
|
|
|
# Ignore NFS shared folders
|
|
|
|
next if data[:nfs]
|
|
|
|
|
|
|
|
# This to prevent overwriting the actual shared folders data
|
|
|
|
result[id] = data.dup
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Prepares the shared folders by verifying they exist and creating them
|
|
|
|
# if they don't.
|
|
|
|
def prepare_folders
|
|
|
|
shared_folders.each do |id, options|
|
|
|
|
hostpath = Pathname.new(options[:hostpath]).expand_path(@env[:root_path])
|
|
|
|
|
|
|
|
if !hostpath.directory? && options[:create]
|
|
|
|
# Host path doesn't exist, so let's create it.
|
|
|
|
@logger.debug("Host path doesn't exist, creating: #{hostpath}")
|
|
|
|
|
|
|
|
begin
|
|
|
|
hostpath.mkpath
|
|
|
|
rescue Errno::EACCES
|
|
|
|
raise Vagrant::Errors::SharedFolderCreateFailed,
|
|
|
|
:path => hostpath.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-06 01:08:02 +00:00
|
|
|
def add_override_configs
|
2013-03-11 03:13:48 +00:00
|
|
|
@env[:ui].info I18n.t("vagrant.actions.lxc.share_folders.preparing")
|
2013-03-04 01:42:18 +00:00
|
|
|
|
|
|
|
folders = []
|
|
|
|
shared_folders.each do |id, data|
|
|
|
|
folders << {
|
|
|
|
:name => id,
|
|
|
|
:hostpath => File.expand_path(data[:hostpath], @env[:root_path]),
|
|
|
|
:guestpath => data[:guestpath]
|
|
|
|
}
|
2013-03-11 03:13:48 +00:00
|
|
|
@env[:ui].info(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
|
|
|
|
:guest_path => data[:guestpath]))
|
2013-03-04 01:42:18 +00:00
|
|
|
end
|
|
|
|
config = @env[:machine].provider_config
|
2013-04-05 05:23:30 +00:00
|
|
|
@env[:machine].provider.driver.share_folders(folders, config)
|
2013-03-04 01:42:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|