Can now specify the UID/GID of the shared folders from the Vagrantfile

This commit is contained in:
Mitchell Hashimoto 2010-03-15 12:33:03 -07:00
parent 51116438a7
commit 5bdabbc8c8
5 changed files with 50 additions and 6 deletions

View File

@ -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'

View File

@ -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

View File

@ -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 = {}

View File

@ -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'

View File

@ -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