diff --git a/config/default.rb b/config/default.rb index 97c051cc0..17b95a3a0 100644 --- a/config/default.rb +++ b/config/default.rb @@ -18,6 +18,8 @@ Vagrant::Config.run do |config| config.vm.forward_port("ssh", 22, 2222) config.vm.disk_image_format = 'VMDK' config.vm.provisioner = nil + config.vm.shared_folder_uid = nil + config.vm.shared_folder_gid = nil config.package.name = 'vagrant' config.package.extension = '.box' diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index 1ca54d525..8c81c578d 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -54,10 +54,16 @@ module Vagrant # Note: This method seems pretty OS-specific and could also use # some configuration options. For now its duct tape and "works" # but should be looked at in the future. - attempts = 0 + # Determine the permission string to attach to the mount command + perms = [] + perms << "uid=#{Vagrant.config.vm.shared_folder_uid}" if Vagrant.config.vm.shared_folder_uid + perms << "gid=#{Vagrant.config.vm.shared_folder_gid}" if Vagrant.config.vm.shared_folder_gid + perms = " -o #{perms.join(",")}" if !perms.empty? + + attempts = 0 while true - result = ssh.exec!("sudo mount -t vboxsf #{name} #{guestpath}") do |ch, type, data| + result = ssh.exec!("sudo mount -t vboxsf#{perms} #{name} #{guestpath}") do |ch, type, data| # net/ssh returns the value in ch[:result] (based on looking at source) ch[:result] = !!(type == :stderr && data =~ /No such device/i) end diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index 37eb4c8a7..d62f49562 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -81,6 +81,8 @@ module Vagrant attr_accessor :hd_location attr_accessor :disk_image_format attr_accessor :provisioner + attr_accessor :shared_folder_uid + attr_accessor :shared_folder_gid def initialize @forwarded_ports = {} diff --git a/test/test_helper.rb b/test/test_helper.rb index 8ef0f667b..9196b3aba 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -23,7 +23,7 @@ class Test::Unit::TestCase Vagrant::Config.reset! Vagrant::Config.run do |config| - config.vagrant.dotfile_name = ".hobo" + config.vagrant.dotfile_name = ".vagrant" config.ssh.username = "foo" config.ssh.password = "bar" @@ -36,9 +36,11 @@ class Test::Unit::TestCase config.vm.box = "foo" config.vm.box_ovf = "box.ovf" config.vm.base_mac = "42" - config.vm.project_directory = "/hobo" + config.vm.project_directory = "/vagrant" config.vm.disk_image_format = 'VMDK' config.vm.forward_port("ssh", 22, 2222) + config.vm.shared_folder_uid = nil + config.vm.shared_folder_gid = nil config.package.name = 'vagrant' config.package.extension = '.box' @@ -48,9 +50,9 @@ class Test::Unit::TestCase config.chef.validation_key_path = "validation.pem" config.chef.client_key_path = "/zoo/foo/bar.pem" config.chef.cookbooks_path = "cookbooks" - config.chef.provisioning_path = "/tmp/hobo-chef" + config.chef.provisioning_path = "/tmp/vagrant-chef" config.chef.json = { - :recipes => ["hobo_main"] + :recipes => ["vagrant_main"] } config.vagrant.home = '~/.home' diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index 5de4e8764..b8a5d8b3c 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -154,5 +154,37 @@ class SharedFoldersActionTest < Test::Unit::TestCase mount_folder } end + + should "add uid to mount if set" do + uid = "foo" + mock_config do |config| + config.vm.shared_folder_uid = uid + end + + @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid} #{@name} #{@guestpath}").returns(@success_return) + mount_folder + end + + should "add gid to mount if set" do + gid = "foo" + mock_config do |config| + config.vm.shared_folder_gid = gid + end + + @ssh.expects(:exec!).with("sudo mount -t vboxsf -o gid=#{gid} #{@name} #{@guestpath}").returns(@success_return) + mount_folder + end + + should "add uid AND gid to mount if set" do + uid = "foo" + gid = "bar" + mock_config do |config| + config.vm.shared_folder_uid = uid + config.vm.shared_folder_gid = gid + end + + @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{uid},gid=#{gid} #{@name} #{@guestpath}").returns(@success_return) + mount_folder + end end end