Always ensure remote destination directory exists

This commit is contained in:
Chris Roberts 2019-02-26 08:54:49 -08:00
parent 6b105d704d
commit e2b6a6645c
2 changed files with 14 additions and 2 deletions

View File

@ -317,10 +317,11 @@ module VagrantPlugins
else
dest = to
if to.end_with?(File::SEPARATOR)
create_remote_directory(dest)
dest = File.join(to, File.basename(path))
end
end
@logger.debug("Ensuring remote directory exists for destination upload")
create_remote_directory(File.dirname(dest))
@logger.debug("Uploading file #{path} to remote #{dest}")
upload_file = File.open(path, "rb")
begin

View File

@ -547,13 +547,24 @@ describe VagrantPlugins::CommunicatorSSH::Communicator do
file = Tempfile.new('vagrant-test')
begin
expect(scp).to receive(:upload!).with(instance_of(File), "/destination/dir/#{File.basename(file.path)}")
expect(communicator).to receive(:create_remote_directory).with("/destination/dir/")
expect(communicator).to receive(:create_remote_directory).with("/destination/dir")
communicator.upload(file.path, "/destination/dir/")
ensure
file.delete
end
end
it "creates remote directory path to destination on upload" do
file = Tempfile.new('vagrant-test')
begin
expect(scp).to receive(:upload!).with(instance_of(File), "/destination/dir/file.txt")
expect(communicator).to receive(:create_remote_directory).with("/destination/dir")
communicator.upload(file.path, "/destination/dir/file.txt")
ensure
file.delete
end
end
it "raises custom error on permission errors" do
file = Tempfile.new('vagrant-test')
begin