From 7517faa9ee8221dd0ef5c1c07a1074fe9b0046d1 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Mon, 7 Jan 2019 09:01:51 -0600 Subject: [PATCH 1/4] Remove tmpdir after rsync completes --- plugins/synced_folders/rsync/helper.rb | 3 +++ test/unit/plugins/synced_folders/rsync/helper_test.rb | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index 8eba835ee..b93f85a2a 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -1,3 +1,4 @@ +require "fileutils" require "ipaddr" require "shellwords" require "tmpdir" @@ -232,6 +233,8 @@ module VagrantPlugins message: err.to_s end end + ensure + FileUtils.remove_entry_secure(controlpath) if controlpath end # Check if rsync versions support using chown option diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 244039a1d..63ce97c21 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -293,6 +293,10 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do }.and_return(result) subject.rsync_single(machine, ssh_info, opts) + + unless Vagrant::Util::Platform.windows? + expect(File.exist?("/tmp/vagrant-rsync-12345")).to be_falsey + end end end end From 45ca16ffd53bcd467f00f27254b04bb2b3921dbf Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 22 Feb 2019 12:38:23 -0800 Subject: [PATCH 2/4] Add rsync helper test for linux machines --- test/unit/plugins/synced_folders/rsync/helper_test.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 63ce97c21..9300b9458 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -292,11 +292,8 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do expect(args[9]).to include("ControlPath=/tmp/vagrant-rsync-12345") }.and_return(result) + expect(FileUtils).to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345").and_return(true) subject.rsync_single(machine, ssh_info, opts) - - unless Vagrant::Util::Platform.windows? - expect(File.exist?("/tmp/vagrant-rsync-12345")).to be_falsey - end end end end From 401a571642e2d5355fa7b9e2b7c2b19e21258884 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 22 Feb 2019 12:44:46 -0800 Subject: [PATCH 3/4] Add windows platform test for ensuring tmp file does not exist --- .../plugins/synced_folders/rsync/helper_test.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 9300b9458..860ea0403 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -295,6 +295,19 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do expect(FileUtils).to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345").and_return(true) subject.rsync_single(machine, ssh_info, opts) end + + it "does not create tmp dir on windows platforms" do + allow(Vagrant::Util::Platform).to receive(:windows?).and_return(true) + allow(Dir).to receive(:mktmpdir).with("vagrant-rsync-"). + and_return("/tmp/vagrant-rsync-12345") + + expect(Vagrant::Util::Subprocess).to receive(:execute).with(any_args) { |*args| + expect(args).not_to include("ControlPath=/tmp/vagrant-rsync-12345") + }.and_return(result) + + expect(FileUtils).not_to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345") + subject.rsync_single(machine, ssh_info, opts) + end end end From 3b540e502feb6576770ae6bbb4358e6f165cd57a Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Tue, 26 Feb 2019 09:08:56 -0800 Subject: [PATCH 4/4] Force removal of rsync tmp dir Force delete entry to prevent any potentail failures when trying to clean up the tmp dir from rsync --- plugins/synced_folders/rsync/helper.rb | 2 +- test/unit/plugins/synced_folders/rsync/helper_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/synced_folders/rsync/helper.rb b/plugins/synced_folders/rsync/helper.rb index b93f85a2a..c23cd1d53 100644 --- a/plugins/synced_folders/rsync/helper.rb +++ b/plugins/synced_folders/rsync/helper.rb @@ -234,7 +234,7 @@ module VagrantPlugins end end ensure - FileUtils.remove_entry_secure(controlpath) if controlpath + FileUtils.remove_entry_secure(controlpath, true) if controlpath end # Check if rsync versions support using chown option diff --git a/test/unit/plugins/synced_folders/rsync/helper_test.rb b/test/unit/plugins/synced_folders/rsync/helper_test.rb index 860ea0403..e50ae872c 100644 --- a/test/unit/plugins/synced_folders/rsync/helper_test.rb +++ b/test/unit/plugins/synced_folders/rsync/helper_test.rb @@ -292,7 +292,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do expect(args[9]).to include("ControlPath=/tmp/vagrant-rsync-12345") }.and_return(result) - expect(FileUtils).to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345").and_return(true) + expect(FileUtils).to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345", true).and_return(true) subject.rsync_single(machine, ssh_info, opts) end @@ -305,7 +305,7 @@ describe VagrantPlugins::SyncedFolderRSync::RsyncHelper do expect(args).not_to include("ControlPath=/tmp/vagrant-rsync-12345") }.and_return(result) - expect(FileUtils).not_to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345") + expect(FileUtils).not_to receive(:remove_entry_secure).with("/tmp/vagrant-rsync-12345", true) subject.rsync_single(machine, ssh_info, opts) end end