From 5eef1524d78ebb9b6c1c123a6a440c9c2eb3ca0e Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 4 May 2014 20:51:53 -0300 Subject: [PATCH] driver: Use relative guest paths for synced folders Closes GH-258 --- lib/vagrant-lxc/driver.rb | 10 ++++++---- spec/unit/driver_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 7427c92..03f80d5 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -67,11 +67,13 @@ module Vagrant end def share_folder(host_path, guest_path, mount_options = nil) - guest_path = rootfs_path.join(guest_path.gsub(/^\//, '')) - unless guest_path.directory? + guest_path = guest_path.gsub(/^\//, '') + guest_full_path = rootfs_path.join(guest_path) + + unless guest_full_path.directory? begin - @logger.debug("Guest path doesn't exist, creating: #{guest_path}") - @sudo_wrapper.run('mkdir', '-p', guest_path.to_s) + @logger.debug("Guest path doesn't exist, creating: #{guest_full_path}") + @sudo_wrapper.run('mkdir', '-p', guest_full_path.to_s) rescue Errno::EACCES raise Vagrant::Errors::SharedFolderCreateFailed, :path => guest_path.to_s end diff --git a/spec/unit/driver_spec.rb b/spec/unit/driver_spec.rb index b1089c1..861a629 100644 --- a/spec/unit/driver_spec.rb +++ b/spec/unit/driver_spec.rb @@ -151,7 +151,7 @@ describe Vagrant::LXC::Driver do 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(:expected_guest_path) { "#{rootfs_path}/vagrant" } + let(:expected_guest_path) { "vagrant" } let(:sudo_wrapper) { double(Vagrant::LXC::SudoWrapper, run: true) } subject { described_class.new('name', sudo_wrapper) } @@ -162,7 +162,7 @@ describe Vagrant::LXC::Driver do end it "creates guest folder under container's rootfs" do - expect(sudo_wrapper).to have_received(:run).with("mkdir", "-p", expected_guest_path) + expect(sudo_wrapper).to have_received(:run).with("mkdir", "-p", "#{rootfs_path}/#{expected_guest_path}") end it 'adds a mount.entry to its local customizations' do @@ -175,7 +175,7 @@ describe Vagrant::LXC::Driver do it 'supports additional mount options' do expect(subject.customizations).to include [ 'mount.entry', - "#{ro_rw_folder[:hostpath]} #{rootfs_path}/vagrant/ro_rw none ro,rw 0 0" + "#{ro_rw_folder[:hostpath]} vagrant/ro_rw none ro,rw 0 0" ] end end