synced_folder: Support for mount_options

This commit is contained in:
Fabio Rehm 2014-03-13 23:36:15 -03:00
parent 623eb1570a
commit 20d4547044
3 changed files with 16 additions and 6 deletions

View file

@ -61,12 +61,12 @@ module Vagrant
end end
def share_folders(folders) def share_folders(folders)
folders.each do |folder| folders.each do |f|
share_folder(folder[:hostpath], folder[:guestpath]) share_folder(f[:hostpath], f[:guestpath], f.fetch(:mount_options, 'bind'))
end end
end end
def share_folder(host_path, guest_path) def share_folder(host_path, guest_path, mount_options = ['bind'])
guest_path = rootfs_path.join(guest_path.gsub(/^\//, '')) guest_path = rootfs_path.join(guest_path.gsub(/^\//, ''))
unless guest_path.directory? unless guest_path.directory?
begin begin
@ -77,7 +77,8 @@ module Vagrant
end end
end end
@customizations << ['mount.entry', "#{host_path} #{guest_path} none bind 0 0"] mount_options = Array(mount_options)
@customizations << ['mount.entry', "#{host_path} #{guest_path} none #{mount_options.join(',')} 0 0"]
end end
def start(customizations) def start(customizations)

View file

@ -25,7 +25,8 @@ module Vagrant
end end
end end
machine.provider.driver.share_folder(host_path, guest_path) mount_opts = data[:mount_options]
machine.provider.driver.share_folder(host_path, guest_path, mount_opts)
# Guest path specified, so mount the folder to specified point # Guest path specified, so mount the folder to specified point
machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry", machine.ui.detail(I18n.t("vagrant.actions.vm.share_folders.mounting_entry",
guestpath: data[:guestpath], guestpath: data[:guestpath],

View file

@ -140,7 +140,8 @@ describe Vagrant::LXC::Driver do
describe 'folder sharing' do describe 'folder sharing' do
let(:shared_folder) { {guestpath: '/vagrant', hostpath: '/path/to/host/dir'} } let(:shared_folder) { {guestpath: '/vagrant', hostpath: '/path/to/host/dir'} }
let(:folders) { [shared_folder] } let(:ro_rw_folder) { {guestpath: '/vagrant/ro_rw', hostpath: '/path/to/host/dir', mount_options: ['ro', 'rw']} }
let(:folders) { [shared_folder, ro_rw_folder] }
let(:rootfs_path) { Pathname('/path/to/rootfs') } let(:rootfs_path) { Pathname('/path/to/rootfs') }
let(:expected_guest_path) { "#{rootfs_path}/vagrant" } let(:expected_guest_path) { "#{rootfs_path}/vagrant" }
let(:sudo_wrapper) { double(Vagrant::LXC::SudoWrapper, run: true) } let(:sudo_wrapper) { double(Vagrant::LXC::SudoWrapper, run: true) }
@ -162,5 +163,12 @@ describe Vagrant::LXC::Driver do
"#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0" "#{shared_folder[:hostpath]} #{expected_guest_path} none bind 0 0"
] ]
end end
it 'supports additional mount options' do
subject.customizations.should include [
'mount.entry',
"#{ro_rw_folder[:hostpath]} #{rootfs_path}/vagrant/ro_rw none ro,rw 0 0"
]
end
end end
end end