Make parent directories when uploading to FTP

This commit is contained in:
Seth Vargo 2015-01-04 18:06:51 -05:00
parent 6a3d99a9a2
commit f11ec8ff1a
1 changed files with 15 additions and 4 deletions

View File

@ -1,3 +1,5 @@
require "pathname"
module VagrantPlugins
module FTPPush
class Adapter
@ -68,15 +70,24 @@ module VagrantPlugins
def upload(local, 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
#