Merge pull request #7154 from mitchellh/pr-6316

Create parent directories during ftp push
This commit is contained in:
Seth Vargo 2016-03-17 20:52:46 -05:00
commit d9b5e0e97d
1 changed files with 18 additions and 1 deletions

View File

@ -106,6 +106,7 @@ module VagrantPlugins
def initialize(*) def initialize(*)
require "net/sftp" require "net/sftp"
super super
@dirs = {}
end end
def default_port def default_port
@ -120,7 +121,23 @@ module VagrantPlugins
end end
def upload(local, remote) def upload(local, remote)
@server.upload!(local, remote, mkdir: true) dir = File.dirname(remote)
fullpath = Pathname.new(dir)
fullpath.descend do |path|
if @dirs[path.to_s].nil?
begin
@server.mkdir!(path.to_s)
# Cache visited directories in a list to avoid duplicate requests
@dirs[path.to_s] = true
rescue Net::SFTP::StatusException => e
# Directory exists, skip...
end
end
end
@server.upload!(local, remote)
end end
end end
end end