From a08d9078da418159e861ae9b723ff2b9723a3a9e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 6 Aug 2014 16:56:09 -0700 Subject: [PATCH] commands/rsync-auto: check machine ID prior to sync [GH-4031] --- CHANGELOG.md | 1 + .../rsync/command/rsync_auto.rb | 7 +++++++ .../rsync/command/rsync_auto_test.rb | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc548576b..cd513f3d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ BUG FIXES: but this fixes a few. [GH-4159] - core: Fix crash case when destroying with an invalid provisioner. [GH-4281] - commands/package: base package won't crash with exception [GH-4017] + - commands/rsync-auto: Destroyed machines won't raise exceptions. [GH-4031] - communicators/winrm: Support `mkdir` [GH-4271] - guests/centos: Fix issues when NFS client is installed by restarting NFS [GH-4088] diff --git a/plugins/synced_folders/rsync/command/rsync_auto.rb b/plugins/synced_folders/rsync/command/rsync_auto.rb index c9d82a969..573e18430 100644 --- a/plugins/synced_folders/rsync/command/rsync_auto.rb +++ b/plugins/synced_folders/rsync/command/rsync_auto.rb @@ -156,6 +156,13 @@ module VagrantPlugins # Sync all the folders that need to be synced tosync.each do |folders| folders.each do |opts| + # Reload so we get the latest ID + opts[:machine].reload + if !opts[:machine].id || opts[:machine].id == "" + # Skip since we can't get SSH info without an ID + next + end + ssh_info = opts[:machine].ssh_info begin RsyncHelper.rsync_single(opts[:machine], ssh_info, opts[:opts]) diff --git a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb index 7324b7962..b1e1a7451 100644 --- a/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb +++ b/test/unit/plugins/synced_folders/rsync/command/rsync_auto_test.rb @@ -29,6 +29,8 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do def machine_stub(name) double(name).tap do |m| + m.stub(id: "foo") + m.stub(reload: nil) m.stub(ssh_info: ssh_info) m.stub(ui: double("ui")) @@ -120,5 +122,22 @@ describe VagrantPlugins::SyncedFolderRSync::Command::RsyncAuto do expect { subject.callback(paths, m, a, r) }. to_not raise_error end + + it "doesn't sync machines with no ID" do + paths["/foo"] = [ + { machine: machine_stub("m1"), opts: double("opts_m1") }, + ] + + paths["/foo"].each do |data| + data[:machine].stub(id: nil) + expect(helper_class).to_not receive(:rsync_single) + end + + m = [] + a = [] + r = ["/foo/bar"] + expect { subject.callback(paths, m, a, r) }. + to_not raise_error + end end end