From 608bc7c0eb87a1c1570de5fdd2ed43be95c51fa5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 16 Jul 2013 16:23:33 -0700 Subject: [PATCH] NFS exports with single quotes now work properly [GH-1166] --- CHANGELOG.md | 1 + plugins/guests/linux/cap/mount_nfs.rb | 4 +++- plugins/hosts/bsd/host.rb | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f29acaa..12588d1a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ BUG FIXES: - SSH channel is closed after the exit status is received, potentially eliminating any SSH hangs. [GH-603] - Fix regression where VirtualBox detection wasn't working anymore. [GH-1918] + - NFS shared folders with single quotes in their name now work properly. [GH-1166] ## 1.2.3 (July 9, 2013) diff --git a/plugins/guests/linux/cap/mount_nfs.rb b/plugins/guests/linux/cap/mount_nfs.rb index 69d4e92f2..fee372e82 100644 --- a/plugins/guests/linux/cap/mount_nfs.rb +++ b/plugins/guests/linux/cap/mount_nfs.rb @@ -16,7 +16,9 @@ module VagrantPlugins machine.communicate.sudo("mkdir -p #{expanded_guest_path}") # Mount - mount_command = "mount -o vers=#{opts[:nfs_version]} #{ip}:'#{opts[:hostpath]}' #{expanded_guest_path}" + hostpath = opts[:hostpath].dup + hostpath.gsub!("'", "'\\\\''") + mount_command = "mount -o vers=#{opts[:nfs_version]} #{ip}:'#{hostpath}' #{expanded_guest_path}" retryable(:on => Vagrant::Errors::LinuxNFSMountFailed, :tries => 5, :sleep => 2) do machine.communicate.sudo(mount_command, diff --git a/plugins/hosts/bsd/host.rb b/plugins/hosts/bsd/host.rb index e51878ade..c3773add6 100644 --- a/plugins/hosts/bsd/host.rb +++ b/plugins/hosts/bsd/host.rb @@ -46,7 +46,8 @@ module VagrantPlugins @logger.debug("Compiling map of sub-directories for NFS exports...") dirmap = {} folders.each do |_, opts| - hostpath = opts[:hostpath] + hostpath = opts[:hostpath].dup + hostpath.gsub!('"', '\"') found = false dirmap.each do |dirs, diropts| @@ -95,7 +96,8 @@ module VagrantPlugins # Output the rendered template into the exports output.split("\n").each do |line| - line = line.gsub('"', '\"') + line.gsub!('"', '\"') + line.gsub!("'", "'\\\\''") system(%Q[sudo su root -c "echo '#{line}' >> /etc/exports"]) end