Merge pull request #8756 from briancain/rsync-auto-docker-provider-fixes

Only rsync-auto current working dir with docker provider
This commit is contained in:
Brian Cain 2017-07-06 15:49:34 -07:00 committed by GitHub
commit 1bcba57eb7
3 changed files with 82 additions and 16 deletions

View File

@ -48,6 +48,9 @@ module VagrantPlugins
paths = {} paths = {}
ignores = [] ignores = []
with_target_vms(argv) do |machine| with_target_vms(argv) do |machine|
next if machine.state.id == :not_created
cwd = machine.env.cwd.to_s
if machine.provider.capability?(:proxy_machine) if machine.provider.capability?(:proxy_machine)
proxy = machine.provider.capability(:proxy_machine) proxy = machine.provider.capability(:proxy_machine)
if proxy if proxy
@ -70,6 +73,21 @@ module VagrantPlugins
folders = cached[:rsync] folders = cached[:rsync]
next if !folders || folders.empty? next if !folders || folders.empty?
# NOTE: This check is required with boot2docker since all containers
# share the same virtual machine. This prevents rsync-auto from
# syncing all known containers with rsync to the boot2docker vm
# and only syncs the current working dirs folders.
sync_folders = {}
folders.each do |id, folder_opts|
if cwd != folder_opts[:hostpath]
machine.ui.info(I18n.t("vagrant.rsync_auto_remove_folder",
folder: folder_opts[:hostpath]))
else
sync_folders[id] = folder_opts
end
end
folders = sync_folders
# Get the SSH info for this machine so we can do an initial # Get the SSH info for this machine so we can do an initial
# sync to the VM. # sync to the VM.
ssh_info = machine.ssh_info ssh_info = machine.ssh_info

View File

@ -218,6 +218,8 @@ en:
have specified `rsync_auto` to be false. have specified `rsync_auto` to be false.
rsync_auto_path: |- rsync_auto_path: |-
Watching: %{path} Watching: %{path}
rsync_auto_remove_folder: |-
Not syncing %{folder} as it is not part of the current working directory.
rsync_auto_rsync_error: |- rsync_auto_rsync_error: |-
There was an error while executing rsync. The error is shown below. There was an error while executing rsync. The error is shown below.
This may not be critical since rsync sometimes fails, but if this message This may not be critical since rsync sometimes fails, but if this message

View File

@ -13,17 +13,18 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
env.create_vagrant_env env.create_vagrant_env
end end
let(:synced_folders) { {} } let(:synced_folders_empty) { {} }
let(:synced_folders_dupe) { {"1234":
{type: "rsync",
exclude: false,
hostpath: "/Users/brian/code/vagrant-sandbox"},
"5678":
{type: "rsync",
exclude: false,
hostpath: "/Not/The/Same/Path"}} }
let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper } let(:helper_class) { VagrantPlugins::SyncedFolderRSync::RsyncHelper }
subject do
described_class.new(argv, iso_env).tap do |s|
s.stub(synced_folders: synced_folders)
end
end
describe "#callback" do
let(:paths) { {} } let(:paths) { {} }
let(:ssh_info) {{}} let(:ssh_info) {{}}
@ -32,12 +33,57 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do
m.stub(id: "foo") m.stub(id: "foo")
m.stub(reload: nil) m.stub(reload: nil)
m.stub(ssh_info: ssh_info) m.stub(ssh_info: ssh_info)
m.stub(ui: double("ui")) m.stub(ui: iso_env.ui)
m.stub(provider: double("provider"))
m.stub(state: double("state", id: :not_created))
m.stub(env: iso_env)
m.ui.stub(error: nil) m.ui.stub(error: nil)
end end
end end
subject do
described_class.new(argv, iso_env).tap
end
describe "#execute" do
let (:machine) { machine_stub("m") }
let (:cached_folders) { { rsync: synced_folders_dupe } }
before do
allow(subject).to receive(:with_target_vms) { |&block| block.call machine }
end
it "does not sync folders outside of the cwd" do
allow(machine.ui).to receive(:info)
allow(machine.state).to receive(:id).and_return(:created)
allow(machine.env).to receive(:cwd).
and_return("/Users/brian/code/vagrant-sandbox")
allow(machine.provider).to receive(:capability?).and_return(false)
allow(subject).to receive(:synced_folders).
with(machine, cached: true).and_return(cached_folders)
allow(helper_class).to receive(:rsync_single).and_return(true)
allow(Vagrant::Util::Busy).to receive(:busy).and_return(true)
allow(Listen).to receive(:to).and_return(true)
expect(machine.ui).to receive(:info).
with("Not syncing /Not/The/Same/Path as it is not part of the current working directory.")
expect(helper_class).to receive(:rsync_single)
subject.execute()
end
end
subject do
described_class.new(argv, iso_env).tap do |s|
s.stub(synced_folders: synced_folders_empty)
end
end
describe "#callback" do
it "syncs modified folders to the proper path" do it "syncs modified folders to the proper path" do
paths["/foo"] = [ paths["/foo"] = [
{ machine: machine_stub("m1"), opts: double("opts_m1") }, { machine: machine_stub("m1"), opts: double("opts_m1") },