Merge pull request #9952 from chrisroberts/f-ftp-push-toomanyfiles

Provide custom error when attempting to push too many files with FTP
This commit is contained in:
Chris Roberts 2018-07-06 16:50:56 -07:00 committed by GitHub
commit 41d4c9aad4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 6 deletions

View File

@ -0,0 +1,13 @@
module VagrantPlugins
module FTPPush
module Errors
class Error < Vagrant::Errors::VagrantError
error_namespace("ftp_push.errors")
end
class TooManyFiles < Error
error_key(:too_many_files)
end
end
end
end

View File

@ -9,3 +9,8 @@ en:
config.push.define "ftp" do |push|
push.%{attribute} = "..."
end
too_many_files: |-
The configured directory for Vagrant FTP push contains too many files
to successfully complete the command. This can be resolved by either
removing extraneous files from the configured directory, or updating
the `dir` configuration option to a subdirectory.

View File

@ -2,6 +2,7 @@ require "net/ftp"
require "pathname"
require_relative "adapter"
require_relative "errors"
module VagrantPlugins
module FTPPush
@ -17,12 +18,17 @@ module VagrantPlugins
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
files = nil
begin
files = Hash[*all_files.flat_map do |file|
relative_path = relative_path_for(file, config.dir)
destination = File.join(config.destination, relative_path)
file = File.expand_path(file, env.root_path)
[file, destination]
end]
rescue SystemStackError
raise Errors::TooManyFiles
end
ftp = "#{config.username}@#{config.host}:#{config.destination}"
env.ui.info "Uploading #{env.root_path} to #{ftp}"

View File

@ -73,6 +73,11 @@ describe VagrantPlugins::FTPPush::Push do
subject.push
expect(server.files).to eq(%w(Gemfile data.txt))
end
it "raises informative exception when too many files to process" do
expect(subject).to receive(:all_files).and_raise(SystemStackError)
expect{ subject.push }.to raise_error(VagrantPlugins::FTPPush::Errors::TooManyFiles)
end
end
describe "#connect" do