Shared folder UID/GID now defaults to the SSH username

This commit is contained in:
Mitchell Hashimoto 2010-03-15 15:13:07 -07:00
parent 0062207ab3
commit 83ddfa6695
4 changed files with 43 additions and 24 deletions

View File

@ -57,8 +57,8 @@ module Vagrant
# Determine the permission string to attach to the mount command # Determine the permission string to attach to the mount command
perms = [] perms = []
perms << "uid=#{Vagrant.config.vm.shared_folder_uid}" if Vagrant.config.vm.shared_folder_uid perms << "uid=#{Vagrant.config.vm.shared_folder_uid}"
perms << "gid=#{Vagrant.config.vm.shared_folder_gid}" if Vagrant.config.vm.shared_folder_gid perms << "gid=#{Vagrant.config.vm.shared_folder_gid}"
perms = " -o #{perms.join(",")}" if !perms.empty? perms = " -o #{perms.join(",")}" if !perms.empty?
attempts = 0 attempts = 0

View File

@ -103,6 +103,14 @@ module Vagrant
raise Exception.new("disk_storage must be set to a directory") unless File.directory?(val) raise Exception.new("disk_storage must be set to a directory") unless File.directory?(val)
@hd_location=val @hd_location=val
end 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 end
class PackageConfig < Base class PackageConfig < Base

View File

@ -119,7 +119,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
end end
should "execute the proper mount command" do 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 mount_folder
end end
@ -155,27 +155,7 @@ class SharedFoldersActionTest < Test::Unit::TestCase
} }
end end
should "add uid to mount if set" do should "add uid AND gid to mount" 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" uid = "foo"
gid = "bar" gid = "bar"
mock_config do |config| mock_config do |config|

View File

@ -193,4 +193,35 @@ class ConfigTest < Test::Unit::TestCase
assert_equal "result", @config.home assert_equal "result", @config.home
end end
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 end