NFS shared folders can have the :create flag, too [GH-667]

This commit is contained in:
Mitchell Hashimoto 2012-01-24 21:48:42 -08:00
parent e6ea1c6340
commit 0576d6e817
2 changed files with 32 additions and 7 deletions

View File

@ -6,6 +6,8 @@
configure it on the guest. [GH-663] configure it on the guest. [GH-663]
- NFS shared folder guest paths can now contain shell expansion characters - NFS shared folder guest paths can now contain shell expansion characters
such as `~`. such as `~`.
- NFS shared folders with a `:create` flag will have their host folders
properly created if they don't exist. [GH-667]
## 0.9.3 (January 24, 2012) ## 0.9.3 (January 24, 2012)

View File

@ -1,3 +1,8 @@
require 'fileutils'
require 'pathname'
require 'log4r'
module Vagrant module Vagrant
module Action module Action
module VM module VM
@ -15,6 +20,7 @@ module Vagrant
# #
class NFS class NFS
def initialize(app,env) def initialize(app,env)
@logger = Log4r::Logger.new("vagrant::action::vm::nfs")
@app = app @app = app
@env = env @env = env
@ -46,18 +52,35 @@ module Vagrant
# task. # task.
def extract_folders def extract_folders
# Load the NFS enabled shared folders # Load the NFS enabled shared folders
@folders = @env[:vm].config.vm.shared_folders.inject({}) do |acc, data| @folders = {}
key, opts = data @env[:vm].config.vm.shared_folders.each do |key, opts|
if opts[:nfs] if opts[:nfs]
# Duplicate the options, set the hostpath, and set disabled on the original # Duplicate the options, set the hostpath, and set disabled on the original
# options so the ShareFolders middleware doesn't try to mount it. # options so the ShareFolders middleware doesn't try to mount it.
acc[key] = opts.dup folder = opts.dup
acc[key][:hostpath] = File.expand_path(opts[:hostpath], @env[:root_path]) hostpath = Pathname.new(opts[:hostpath]).expand_path(@env[:root_path])
if !hostpath.directory? && opts[:create]
# Host path doesn't exist, so let's create it.
@logger.debug("Host path doesn't exist, creating: #{hostpath}")
begin
FileUtils.mkpath(hostpath)
rescue Errno::EACCES
raise Errors::SharedFolderCreateFailed, :path => hostpath.to_s
end
end
# Set the hostpath now that it exists.
folder[:hostpath] = hostpath.to_s
# Assign the folder to our instance variable for later use
@folders[key] = folder
# Disable the folder so that regular shared folders don't try to
# mount it.
opts[:disabled] = true opts[:disabled] = true
end end
acc
end end
end end