From 187d8e9cfd8f7796b738bdd20066ae7c1e7d1a3c Mon Sep 17 00:00:00 2001 From: sophia Date: Wed, 5 Aug 2020 15:56:04 -0500 Subject: [PATCH] Allow file provisioner to copy empty folders --- plugins/communicators/ssh/communicator.rb | 3 ++- .../plugins/communicators/ssh/communicator_test.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index da43cb23e..b009cb5ca 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -307,10 +307,11 @@ module VagrantPlugins scp_connect do |scp| uploader = lambda do |path, remote_dest=nil| if File.directory?(path) + dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, "")) + create_remote_directory(dest) Dir.new(path).each do |entry| next if entry == "." || entry == ".." full_path = File.join(path, entry) - dest = File.join(to, path.sub(/^#{Regexp.escape(from)}/, "")) create_remote_directory(dest) uploader.call(full_path, dest) end diff --git a/test/unit/plugins/communicators/ssh/communicator_test.rb b/test/unit/plugins/communicators/ssh/communicator_test.rb index d6e9d2b85..9139f0439 100644 --- a/test/unit/plugins/communicators/ssh/communicator_test.rb +++ b/test/unit/plugins/communicators/ssh/communicator_test.rb @@ -565,6 +565,16 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do end end + it "creates remote directory given an empty directory" do + file = Dir.mktmpdir + begin + expect(communicator).to receive(:create_remote_directory).with("/destination/dir/#{ File.basename(file)}/") + communicator.upload(file, "/destination/dir") + ensure + FileUtils.rm_rf(file) + end + end + it "raises custom error on permission errors" do file = Tempfile.new('vagrant-test') begin