From 2d327055f38e8e481fb74fc198cb5f29e72e24c2 Mon Sep 17 00:00:00 2001 From: Scott Sanders Date: Mon, 30 Jan 2012 19:40:29 +0000 Subject: [PATCH] Do not allow BSD hosts to double-quote in exports This is not allowed on *BSD --- lib/vagrant/hosts/bsd.rb | 3 ++- lib/vagrant/hosts/freebsd.rb | 15 +++++++++++++++ templates/locales/en.yml | 4 ++++ templates/nfs/exports_freebsd.erb | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 templates/nfs/exports_freebsd.erb diff --git a/lib/vagrant/hosts/bsd.rb b/lib/vagrant/hosts/bsd.rb index 4a13ef51b..8794caca4 100644 --- a/lib/vagrant/hosts/bsd.rb +++ b/lib/vagrant/hosts/bsd.rb @@ -24,6 +24,7 @@ module Vagrant @logger = Log4r::Logger.new("vagrant::hosts::bsd") @nfs_restart_command = "sudo nfsd restart" + @nfs_exports_template = "nfs/exports" end def nfs? @@ -33,7 +34,7 @@ module Vagrant end def nfs_export(id, ip, folders) - output = TemplateRenderer.render('nfs/exports', + output = TemplateRenderer.render(@nfs_exports_template, :uuid => id, :ip => ip, :folders => folders) diff --git a/lib/vagrant/hosts/freebsd.rb b/lib/vagrant/hosts/freebsd.rb index 6d0d17329..52abbe252 100644 --- a/lib/vagrant/hosts/freebsd.rb +++ b/lib/vagrant/hosts/freebsd.rb @@ -4,6 +4,10 @@ module Vagrant module Hosts # Represents a FreeBSD host class FreeBSD < BSD + class FreeBSDHostError < Errors::VagrantError + error_namespace("vagrant.hosts.freebsd") + end + include Util include Util::Retryable @@ -16,10 +20,21 @@ module Vagrant 5 end + def nfs_export(id, ip, folders) + folders.each do |folder_name, folder_values| + if folder_values[:hostpath] =~ /\s+/ + raise FreeBSDHostError, :_key => :nfs_whitespace + end + end + + super + end + def initialize(*args) super @nfs_restart_command = "sudo /etc/rc.d/mountd onereload" + @nfs_exports_template = "nfs/exports_freebsd" end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index b85036dff..ba8d93e7f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -554,6 +554,10 @@ en: arch: nfs_export: prepare: "Preparing to edit /etc/exports. Administrator privileges will be required..." + freebsd: + nfs_whitespace: |- + FreeBSD hosts do not support sharing directories with whitespace in + their path. Please adjust your path accordingly. provisioners: chef: diff --git a/templates/nfs/exports_freebsd.erb b/templates/nfs/exports_freebsd.erb new file mode 100644 index 000000000..59dbd83be --- /dev/null +++ b/templates/nfs/exports_freebsd.erb @@ -0,0 +1,5 @@ +# VAGRANT-BEGIN: <%= uuid %> +<% folders.each do |name, opts| %> +<%= opts[:hostpath] %> <%= ip %><% if opts[:map_uid] -%> -alldirs -mapall=<%= [opts[:map_uid],opts[:map_gid]].compact.join(":") %><% end -%> +<% end %> +# VAGRANT-END: <%= uuid %>