:create flag on shared folders will create on host if it doesnt exist [GH-604]
This commit is contained in:
parent
ba5cd9b88a
commit
9cb4597a27
|
@ -31,6 +31,8 @@
|
|||
- Added a "--plain" flag to `vagrant ssh` which will cause Vagrant to not
|
||||
perform any authentication. It will simply `ssh` into the proper IP and
|
||||
port of the virtual machine.
|
||||
- If a shared folder now has a `:create` flag set to `true`, the path on the
|
||||
host will be created if it doesn't exist.
|
||||
- Removed Thor as a dependency for the command line interfaces. This resulted
|
||||
in general speed increases across all command line commands.
|
||||
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
require 'pathname'
|
||||
|
||||
require 'log4r'
|
||||
|
||||
module Vagrant
|
||||
module Action
|
||||
module VM
|
||||
class ShareFolders
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@env = env
|
||||
@logger = Log4r::Logger.new("vagrant::action::vm::share_folders")
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@env = env
|
||||
|
||||
prepare_folders
|
||||
create_metadata
|
||||
|
||||
@app.call(env)
|
||||
|
@ -32,6 +37,20 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
|
||||
# Prepares the shared folders by verifying they exist and creating them
|
||||
# if they don't.
|
||||
def prepare_folders
|
||||
shared_folders.each do |name, 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}")
|
||||
hostpath.mkpath
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_metadata
|
||||
@env[:ui].info I18n.t("vagrant.actions.vm.share_folders.creating")
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'pathname'
|
||||
|
||||
require 'vagrant/config/vm/sub_vm'
|
||||
require 'vagrant/config/vm/provisioner'
|
||||
|
||||
|
@ -52,8 +54,9 @@ Please change your configurations to match this new syntax.
|
|||
|
||||
def share_folder(name, guestpath, hostpath, opts=nil)
|
||||
@shared_folders[name] = {
|
||||
:guestpath => guestpath,
|
||||
:hostpath => hostpath,
|
||||
:guestpath => guestpath.to_s,
|
||||
:hostpath => hostpath.to_s,
|
||||
:create => false,
|
||||
:owner => nil,
|
||||
:group => nil,
|
||||
:nfs => false
|
||||
|
@ -133,7 +136,9 @@ do before is certainly still possible with `VBoxManage` as well.
|
|||
errors.add(I18n.t("vagrant.config.vm.base_mac_invalid")) if env.boxes.find(box) && !base_mac
|
||||
|
||||
shared_folders.each do |name, options|
|
||||
if !File.directory?(File.expand_path(options[:hostpath].to_s, env.root_path))
|
||||
hostpath = Pathname.new(options[:hostpath]).expand_path(env.root_path)
|
||||
|
||||
if !hostpath.directory? && !options[:create]
|
||||
errors.add(I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",
|
||||
:name => name,
|
||||
:path => options[:hostpath]))
|
||||
|
|
Loading…
Reference in New Issue