From 944853ab471a32df2d68a15a6174f61e583858a2 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 16:24:26 -0500 Subject: [PATCH 1/9] Use 21 for the default port --- plugins/pushes/ftp/adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pushes/ftp/adapter.rb b/plugins/pushes/ftp/adapter.rb index f370d411f..9b08a0146 100644 --- a/plugins/pushes/ftp/adapter.rb +++ b/plugins/pushes/ftp/adapter.rb @@ -50,7 +50,7 @@ module VagrantPlugins end def default_port - 20 + 21 end def connect(&block) From e7391359e80d5165b504da8521303ffa3fe06e3f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:05:17 -0500 Subject: [PATCH 2/9] Remove duplicate #parse_host method --- plugins/pushes/ftp/push.rb | 10 -------- test/unit/plugins/pushes/ftp/push_test.rb | 28 ----------------------- 2 files changed, 38 deletions(-) diff --git a/plugins/pushes/ftp/push.rb b/plugins/pushes/ftp/push.rb index 3cf4169a0..90f7df07a 100644 --- a/plugins/pushes/ftp/push.rb +++ b/plugins/pushes/ftp/push.rb @@ -33,16 +33,6 @@ module VagrantPlugins ftp.connect(&block) end - # Parse the host into it's url and port parts. - # @return [Array] - def parse_host(host) - if host.include?(":") - host.split(":", 2) - else - [host, "22"] - end - end - # The list of all files that should be pushed by this push. This method # only returns **files**, not folders or symlinks! # @return [Array] diff --git a/test/unit/plugins/pushes/ftp/push_test.rb b/test/unit/plugins/pushes/ftp/push_test.rb index 5b5ec7c10..39dd6dd79 100644 --- a/test/unit/plugins/pushes/ftp/push_test.rb +++ b/test/unit/plugins/pushes/ftp/push_test.rb @@ -93,34 +93,6 @@ describe VagrantPlugins::FTPPush::Push do end end - describe "#parse_host" do - let(:result) { subject.parse_host(host) } - - context "when no port is given" do - let(:host) { "127.0.0.1" } - - it "returns the url and port 22" do - expect(result).to eq(["127.0.0.1", "22"]) - end - end - - context "when a port is given" do - let(:host) { "127.0.0.1:23456" } - - it "returns the url and port 23456" do - expect(result).to eq(["127.0.0.1", "23456"]) - end - end - - context "when more than more port is given" do - let(:host) { "127.0.0.1:22:33:44" } - - it "returns the url and everything after" do - expect(result).to eq(["127.0.0.1", "22:33:44"]) - end - end - end - describe "#all_files" do before(:all) do @dir = Dir.mktmpdir From e3308753031b733813ab471300feb71b88a8840f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:05:46 -0500 Subject: [PATCH 3/9] Exclude certain directories by default --- plugins/pushes/ftp/push.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/pushes/ftp/push.rb b/plugins/pushes/ftp/push.rb index 90f7df07a..4cf81cda6 100644 --- a/plugins/pushes/ftp/push.rb +++ b/plugins/pushes/ftp/push.rb @@ -7,6 +7,7 @@ module VagrantPlugins module FTPPush class Push < Vagrant.plugin("2", :push) IGNORED_FILES = %w(. ..).freeze + DEFAULT_EXCLUDES = %w(.git .hg .svn .vagrant).freeze def push # Grab files early so if there's an exception or issue, we don't have to @@ -62,7 +63,10 @@ module VagrantPlugins # @param [Array] excludes # the exclude patterns or files def filter_excludes!(list, excludes) - excludes = Array(excludes).flat_map { |e| [e, "#{e}/*"] } + excludes = Array(excludes) + excludes = excludes + DEFAULT_EXCLUDES + excludes = excludes.flat_map { |e| [e, "#{e}/*"] } + list.reject! do |file| basename = relative_path_for(file, config.dir) From fd3c1c6ebb125923e53edc8c95eab1ddc7d8d233 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:06:05 -0500 Subject: [PATCH 4/9] Add a logger when uploading to FTP --- plugins/pushes/ftp/push.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/pushes/ftp/push.rb b/plugins/pushes/ftp/push.rb index 4cf81cda6..d153ae778 100644 --- a/plugins/pushes/ftp/push.rb +++ b/plugins/pushes/ftp/push.rb @@ -9,6 +9,11 @@ module VagrantPlugins IGNORED_FILES = %w(. ..).freeze DEFAULT_EXCLUDES = %w(.git .hg .svn .vagrant).freeze + def initialize(*) + super + @logger = Log4r::Logger.new("vagrant::pushes::ftp") + end + def push # Grab files early so if there's an exception or issue, we don't have to # wait and close the (S)FTP connection as well @@ -20,6 +25,7 @@ module VagrantPlugins connect do |ftp| files.each do |local, remote| + @logger.info "Uploading #{local} => #{remote}" ftp.upload(local, remote) end end From 50c1c0756e3d0ecc67132e6fabddcb899f17b7c8 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:06:16 -0500 Subject: [PATCH 5/9] Expand file paths relative to the root_path --- plugins/pushes/ftp/push.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/pushes/ftp/push.rb b/plugins/pushes/ftp/push.rb index d153ae778..82c4da1e9 100644 --- a/plugins/pushes/ftp/push.rb +++ b/plugins/pushes/ftp/push.rb @@ -20,6 +20,7 @@ module VagrantPlugins files = Hash[*all_files.flat_map do |file| relative_path = relative_path_for(file, config.dir) destination = File.expand_path(File.join(config.destination, relative_path)) + file = File.expand_path(file, env.root_path) [file, destination] end] From 6a3d99a9a2fc42ecbd0c5a99737dec5f7c59589d Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:06:32 -0500 Subject: [PATCH 6/9] Output to the UI when uploading via FTP --- plugins/pushes/ftp/push.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/pushes/ftp/push.rb b/plugins/pushes/ftp/push.rb index 82c4da1e9..7a69c4f02 100644 --- a/plugins/pushes/ftp/push.rb +++ b/plugins/pushes/ftp/push.rb @@ -24,6 +24,9 @@ module VagrantPlugins [file, destination] end] + ftp = "#{config.username}@#{config.host}:#{config.destination}" + env.ui.info "Uploading #{env.root_path} to #{ftp}" + connect do |ftp| files.each do |local, remote| @logger.info "Uploading #{local} => #{remote}" From f11ec8ff1a5ade7b9483822a27709bfb82ab7113 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:06:51 -0500 Subject: [PATCH 7/9] Make parent directories when uploading to FTP --- plugins/pushes/ftp/adapter.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugins/pushes/ftp/adapter.rb b/plugins/pushes/ftp/adapter.rb index 9b08a0146..8a9414376 100644 --- a/plugins/pushes/ftp/adapter.rb +++ b/plugins/pushes/ftp/adapter.rb @@ -1,3 +1,5 @@ +require "pathname" + module VagrantPlugins module FTPPush class Adapter @@ -67,16 +69,25 @@ module VagrantPlugins end def upload(local, remote) - parent = File.dirname(remote) + parent = File.dirname(remote) + fullpath = Pathname.new(File.expand_path(parent, pwd)) - # Create the parent directory if it does not exist - if !@server.list("/").any? { |f| f.start_with?(parent) } - @server.mkdir(parent) + # Create the parent directories if they does not exist (naive mkdir -p) + fullpath.descend do |path| + if @server.list(path.to_s).empty? + @server.mkdir(path.to_s) + end end # Upload the file @server.putbinaryfile(local, remote) end + + private + + def pwd + @pwd ||= @server.pwd + end end # From 6d116cb152f4a7737ee804e49c1d4440a9b8bab9 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:29:59 -0500 Subject: [PATCH 8/9] Fix the default FTP port --- test/unit/plugins/pushes/ftp/adapter_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/plugins/pushes/ftp/adapter_test.rb b/test/unit/plugins/pushes/ftp/adapter_test.rb index 54bacc1d1..e929078cd 100644 --- a/test/unit/plugins/pushes/ftp/adapter_test.rb +++ b/test/unit/plugins/pushes/ftp/adapter_test.rb @@ -54,8 +54,8 @@ describe VagrantPlugins::FTPPush::FTPAdapter do end describe "#default_port" do - it "is 20" do - expect(subject.default_port).to eq(20) + it "is 21" do + expect(subject.default_port).to eq(21) end end From 81de7154e672d0c94cc4ee660b4cca51f7b2d32f Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Sun, 4 Jan 2015 18:36:29 -0500 Subject: [PATCH 9/9] Fix failing test --- test/unit/plugins/pushes/ftp/push_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/plugins/pushes/ftp/push_test.rb b/test/unit/plugins/pushes/ftp/push_test.rb index 39dd6dd79..25d6e1229 100644 --- a/test/unit/plugins/pushes/ftp/push_test.rb +++ b/test/unit/plugins/pushes/ftp/push_test.rb @@ -20,6 +20,11 @@ describe VagrantPlugins::FTPPush::Push do subject { described_class.new(env, config) } + before do + allow(env).to receive(:root_path) + .and_return(File.expand_path("..", __FILE__)) + end + describe "#push" do before(:all) do @server = FakeFtp::Server.new(51234, 21213)