From 83ddfa66952abd5402563841c1b3b9bc77fdde19 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 15 Mar 2010 15:13:07 -0700 Subject: [PATCH] Shared folder UID/GID now defaults to the SSH username --- lib/vagrant/actions/vm/shared_folders.rb | 4 +-- lib/vagrant/config.rb | 8 +++++ .../vagrant/actions/vm/shared_folders_test.rb | 24 ++------------ test/vagrant/config_test.rb | 31 +++++++++++++++++++ 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/lib/vagrant/actions/vm/shared_folders.rb b/lib/vagrant/actions/vm/shared_folders.rb index 8c81c578d..6ebea482c 100644 --- a/lib/vagrant/actions/vm/shared_folders.rb +++ b/lib/vagrant/actions/vm/shared_folders.rb @@ -57,8 +57,8 @@ module Vagrant # 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 << "uid=#{Vagrant.config.vm.shared_folder_uid}" + perms << "gid=#{Vagrant.config.vm.shared_folder_gid}" perms = " -o #{perms.join(",")}" if !perms.empty? attempts = 0 diff --git a/lib/vagrant/config.rb b/lib/vagrant/config.rb index c21d287fe..983a9196c 100644 --- a/lib/vagrant/config.rb +++ b/lib/vagrant/config.rb @@ -103,6 +103,14 @@ module Vagrant raise Exception.new("disk_storage must be set to a directory") unless File.directory?(val) @hd_location=val end + + def shared_folder_uid + @shared_folder_uid || Vagrant.config.ssh.username + end + + def shared_folder_gid + @shared_folder_gid || Vagrant.config.ssh.username + end end class PackageConfig < Base diff --git a/test/vagrant/actions/vm/shared_folders_test.rb b/test/vagrant/actions/vm/shared_folders_test.rb index b8a5d8b3c..8a818c9f4 100644 --- a/test/vagrant/actions/vm/shared_folders_test.rb +++ b/test/vagrant/actions/vm/shared_folders_test.rb @@ -119,7 +119,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase end should "execute the proper mount command" do - @ssh.expects(:exec!).with("sudo mount -t vboxsf #{@name} #{@guestpath}").returns(@success_return) + @ssh.expects(:exec!).with("sudo mount -t vboxsf -o uid=#{Vagrant.config.ssh.username},gid=#{Vagrant.config.ssh.username} #{@name} #{@guestpath}").returns(@success_return) mount_folder end @@ -155,27 +155,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase } 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 + should "add uid AND gid to mount" do uid = "foo" gid = "bar" mock_config do |config| diff --git a/test/vagrant/config_test.rb b/test/vagrant/config_test.rb index ce36a3711..c93ee3e44 100644 --- a/test/vagrant/config_test.rb +++ b/test/vagrant/config_test.rb @@ -193,4 +193,35 @@ class ConfigTest < Test::Unit::TestCase assert_equal "result", @config.home end end + + context "VM configuration" do + setup do + @config = Vagrant::Config::VMConfig.new + @username = "bob" + + mock_config do |config| + config.ssh.username = @username + end + end + + should "return the shared folder UID if set" do + @config.shared_folder_uid = "foo" + assert_equal "foo", @config.shared_folder_uid + end + + should "return the SSH username if UID not set" do + @config.shared_folder_uid = nil + assert_equal @username, @config.shared_folder_uid + end + + should "return the shared folder GID if set" do + @config.shared_folder_gid = "foo" + assert_equal "foo", @config.shared_folder_gid + end + + should "return the SSH username if GID not set" do + @config.shared_folder_gid = nil + assert_equal @username, @config.shared_folder_gid + end + end end