Merge pull request #12645 from hashicorp/fix-push-ftp
Fix VAGRANT_CWD handling in `vagrant push ftp`
This commit is contained in:
commit
885714608d
@ -21,7 +21,7 @@ module VagrantPlugins
|
||||
files = nil
|
||||
begin
|
||||
files = Hash[*all_files.flat_map do |file|
|
||||
relative_path = relative_path_for(file, config.dir)
|
||||
relative_path = relative_path_for(file, base_dir)
|
||||
destination = File.join(config.destination, relative_path)
|
||||
file = File.expand_path(file, env.root_path)
|
||||
[file, destination]
|
||||
@ -31,11 +31,11 @@ module VagrantPlugins
|
||||
end
|
||||
|
||||
ftp = "#{config.username}@#{config.host}:#{config.destination}"
|
||||
env.ui.info "Uploading #{env.root_path} to #{ftp}"
|
||||
env.ui.info "Uploading #{files.length} files to #{env.root_path} to #{ftp}"
|
||||
|
||||
connect do |ftp|
|
||||
files.each do |local, remote|
|
||||
@logger.info "Uploading #{local} => #{remote}"
|
||||
env.ui.info "Uploading #{local} => #{remote}"
|
||||
ftp.upload(local, remote)
|
||||
end
|
||||
end
|
||||
@ -54,7 +54,7 @@ module VagrantPlugins
|
||||
# only returns **files**, not folders or symlinks!
|
||||
# @return [Array<String>]
|
||||
def all_files
|
||||
files = glob("#{config.dir}/**/*") + includes_files
|
||||
files = glob("#{base_dir}/**/*") + includes_files
|
||||
filter_excludes!(files, config.excludes)
|
||||
files.reject! { |f| !File.file?(f) }
|
||||
files
|
||||
@ -64,7 +64,7 @@ module VagrantPlugins
|
||||
# @return [Array<String>]
|
||||
def includes_files
|
||||
includes = config.includes.flat_map do |i|
|
||||
path = absolute_path_for(i, config.dir)
|
||||
path = absolute_path_for(i, base_dir)
|
||||
[path, "#{path}/**/*"]
|
||||
end
|
||||
|
||||
@ -121,6 +121,14 @@ module VagrantPlugins
|
||||
rescue ArgumentError
|
||||
return path
|
||||
end
|
||||
|
||||
def base_dir
|
||||
if Pathname.new(config.dir).absolute?
|
||||
config.dir
|
||||
else
|
||||
File.join(File.expand_path(env.root_path), config.dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -64,6 +64,9 @@ describe VagrantPlugins::FTPPush::Push do
|
||||
.and_return(%w(*.rb))
|
||||
end
|
||||
|
||||
after do
|
||||
server.reset
|
||||
end
|
||||
|
||||
it "pushes the files to the server" do
|
||||
subject.push
|
||||
@ -74,6 +77,31 @@ describe VagrantPlugins::FTPPush::Push do
|
||||
expect(subject).to receive(:all_files).and_raise(SystemStackError)
|
||||
expect{ subject.push }.to raise_error(VagrantPlugins::FTPPush::Errors::TooManyFiles)
|
||||
end
|
||||
|
||||
context "when VAGRANT_CWD is set to something relative" do
|
||||
# this will be the PWD for the test context
|
||||
let(:pwd) { Pathname.new(Dir.mktmpdir("vagrant-ftp-push-pwd")) }
|
||||
|
||||
before do
|
||||
# this path should have a ../ in it since the pwd is another temp dir
|
||||
# and measuring path from one to the other. they're most likely to be
|
||||
# siblings
|
||||
relative_path = Pathname.new(@dir).relative_path_from(pwd)
|
||||
allow(env).to receive(:root_path) { relative_path.to_s }
|
||||
# reset config.dir to its default since it was set absolute above
|
||||
allow(config).to receive(:dir) { "." }
|
||||
end
|
||||
|
||||
it "properly paths out the files to upload" do
|
||||
Vagrant::Util::SafeChdir.safe_chdir(pwd) do
|
||||
subject.push
|
||||
end
|
||||
|
||||
expect(server.files).to eq(%w(Gemfile data.txt))
|
||||
ensure
|
||||
FileUtils.rm_rf(pwd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#connect" do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user