Allow shell expansions in shared folder guest paths again [GH-656]
This commit is contained in:
parent
ac48d270eb
commit
be97cec8b5
|
@ -1,5 +1,6 @@
|
||||||
## 0.9.2 (unreleased)
|
## 0.9.2 (unreleased)
|
||||||
|
|
||||||
|
- Support shell expansions in shared folder guest paths again. [GH-656]
|
||||||
- Fix `forward_agent` not working when outside of blocks. [GH-651]
|
- Fix `forward_agent` not working when outside of blocks. [GH-651]
|
||||||
- Fix issue causing custom guest implementations to not load properly.
|
- Fix issue causing custom guest implementations to not load properly.
|
||||||
- Filter clear screen character out of output on SSH.
|
- Filter clear screen character out of output on SSH.
|
||||||
|
|
|
@ -35,9 +35,29 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount_shared_folder(name, guestpath, options)
|
def mount_shared_folder(name, guestpath, options)
|
||||||
@vm.channel.sudo("mkdir -p #{guestpath}")
|
# Determine the real guest path. Since we use a `sudo` shell everywhere
|
||||||
mount_folder(name, guestpath, options)
|
# else, things like '~' don't expand properly in shared folders. We have
|
||||||
@vm.channel.sudo("chown `id -u #{options[:owner]}`:`id -g #{options[:group]}` #{guestpath}")
|
# to `echo` here to get that path.
|
||||||
|
real_guestpath = nil
|
||||||
|
@vm.channel.execute("echo #{guestpath}") do |type, data|
|
||||||
|
if type == :stdout
|
||||||
|
real_guestpath ||= ""
|
||||||
|
real_guestpath += data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if !real_guestpath
|
||||||
|
# Really strange error case if this happens. Let's throw an error,
|
||||||
|
# tell the user to check the echo output.
|
||||||
|
raise LinuxError, :_key => :guestpath_expand_fail
|
||||||
|
end
|
||||||
|
|
||||||
|
# Chomp off the newline if it exists
|
||||||
|
real_guestpath = real_guestpath.chomp
|
||||||
|
|
||||||
|
@vm.channel.sudo("mkdir -p #{real_guestpath}")
|
||||||
|
mount_folder(name, real_guestpath, options)
|
||||||
|
@vm.channel.sudo("chown `id -u #{options[:owner]}`:`id -g #{options[:group]}` #{real_guestpath}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def mount_nfs(ip, folders)
|
def mount_nfs(ip, folders)
|
||||||
|
|
|
@ -669,6 +669,11 @@ en:
|
||||||
back the logic necessary to set this up. Please report a bug as well as the
|
back the logic necessary to set this up. Please report a bug as well as the
|
||||||
box you're using.
|
box you're using.
|
||||||
linux:
|
linux:
|
||||||
|
guestpath_expand_fail: |-
|
||||||
|
Vagrant failed to determine the shell expansion of the guest path
|
||||||
|
for one of your shared folders. This is an extremely rare error case
|
||||||
|
and most likely indicates an unusual configuration of the guest system.
|
||||||
|
Please report a bug with your Vagrantfile.
|
||||||
mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
|
mount_fail: "Failed to mount shared folders. `vboxsf` was not available."
|
||||||
mount_nfs_fail: |-
|
mount_nfs_fail: |-
|
||||||
Mounting NFS shared folders failed. This is most often caused by the NFS
|
Mounting NFS shared folders failed. This is most often caused by the NFS
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
require File.expand_path("../base", __FILE__)
|
||||||
|
require "acceptance/support/shared/command_examples"
|
||||||
|
|
||||||
|
describe "vagrant shared folders" do
|
||||||
|
include_context "acceptance"
|
||||||
|
|
||||||
|
# This creates an initial environment that is ready for a "vagrant up"
|
||||||
|
def initialize_valid_environment
|
||||||
|
require_box("default")
|
||||||
|
|
||||||
|
assert_execute("vagrant", "box", "add", "base", box_path("default"))
|
||||||
|
assert_execute("vagrant", "init")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should have a '/vagrant' shared folder" do
|
||||||
|
initialize_valid_environment
|
||||||
|
|
||||||
|
# This is the file that will be created from the VM,
|
||||||
|
# but should then exist on the host machine
|
||||||
|
foofile = environment.workdir.join("foo")
|
||||||
|
|
||||||
|
assert_execute("vagrant", "up")
|
||||||
|
foofile.exist?.should_not be,
|
||||||
|
"'foo' should not exist yet."
|
||||||
|
|
||||||
|
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
||||||
|
foofile.exist?.should be, "'foo' should exist since it was touched in the shared folder"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should create a shared folder if the :create flag is set" do
|
||||||
|
initialize_valid_environment
|
||||||
|
|
||||||
|
# Setup the custom Vagrantfile
|
||||||
|
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
||||||
|
f.write(<<-VF)
|
||||||
|
Vagrant::Config.run do |config|
|
||||||
|
config.vm.box = "base"
|
||||||
|
config.vm.share_folder "v-root", "/vagrant", "./data", :create => true
|
||||||
|
end
|
||||||
|
VF
|
||||||
|
end
|
||||||
|
|
||||||
|
data_dir = environment.workdir.join("data")
|
||||||
|
|
||||||
|
# Verify the directory doesn't exist prior, for sanity
|
||||||
|
data_dir.exist?.should_not be
|
||||||
|
|
||||||
|
# Bring up the VM
|
||||||
|
assert_execute("vagrant", "up")
|
||||||
|
|
||||||
|
# Verify the directory exists
|
||||||
|
data_dir.should be_directory
|
||||||
|
|
||||||
|
# Touch a file and verify it is shared
|
||||||
|
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
||||||
|
data_dir.join("foo").exist?.should be
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should properly shell expand relative directories on the guest" do
|
||||||
|
initialize_valid_environment
|
||||||
|
|
||||||
|
# Setup the custom Vagrantfile
|
||||||
|
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
||||||
|
f.write(<<-VF)
|
||||||
|
Vagrant::Config.run do |config|
|
||||||
|
config.vm.box = "base"
|
||||||
|
config.vm.share_folder "v-root", "~/data", "."
|
||||||
|
end
|
||||||
|
VF
|
||||||
|
end
|
||||||
|
|
||||||
|
# Sanity
|
||||||
|
foo_file = environment.workdir.join("foo")
|
||||||
|
foo_file.exist?.should_not be
|
||||||
|
|
||||||
|
# Bring up the VM
|
||||||
|
assert_execute("vagrant", "up")
|
||||||
|
|
||||||
|
# Touch a file in the shared folder we expect and verify
|
||||||
|
# it is shared.
|
||||||
|
assert_execute("vagrant", "ssh", "-c", "touch ~/data/foo")
|
||||||
|
foo_file.exist?.should be
|
||||||
|
end
|
||||||
|
end
|
|
@ -30,48 +30,4 @@ describe "vagrant up", "basics" do
|
||||||
foodir.mkdir
|
foodir.mkdir
|
||||||
assert_execute("vagrant", "up", :chdir => foodir.to_s)
|
assert_execute("vagrant", "up", :chdir => foodir.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should have a '/vagrant' shared folder" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# This is the file that will be created from the VM,
|
|
||||||
# but should then exist on the host machine
|
|
||||||
foofile = environment.workdir.join("foo")
|
|
||||||
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
foofile.exist?.should_not be,
|
|
||||||
"'foo' should not exist yet."
|
|
||||||
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
|
||||||
foofile.exist?.should be, "'foo' should exist since it was touched in the shared folder"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should create a shared folder if the :create flag is set" do
|
|
||||||
initialize_valid_environment
|
|
||||||
|
|
||||||
# Setup the custom Vagrantfile
|
|
||||||
environment.workdir.join("Vagrantfile").open("w+") do |f|
|
|
||||||
f.write(<<-VF)
|
|
||||||
Vagrant::Config.run do |config|
|
|
||||||
config.vm.box = "base"
|
|
||||||
config.vm.share_folder "v-root", "/vagrant", "./data", :create => true
|
|
||||||
end
|
|
||||||
VF
|
|
||||||
end
|
|
||||||
|
|
||||||
data_dir = environment.workdir.join("data")
|
|
||||||
|
|
||||||
# Verify the directory doesn't exist prior, for sanity
|
|
||||||
data_dir.exist?.should_not be
|
|
||||||
|
|
||||||
# Bring up the VM
|
|
||||||
assert_execute("vagrant", "up")
|
|
||||||
|
|
||||||
# Verify the directory exists
|
|
||||||
data_dir.should be_directory
|
|
||||||
|
|
||||||
# Touch a file and verify it is shared
|
|
||||||
assert_execute("vagrant", "ssh", "-c", "touch /vagrant/foo")
|
|
||||||
data_dir.join("foo").exist?.should be
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue