Make parent directories when uploading to FTP
This commit is contained in:
parent
6a3d99a9a2
commit
f11ec8ff1a
|
@ -1,3 +1,5 @@
|
||||||
|
require "pathname"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module FTPPush
|
module FTPPush
|
||||||
class Adapter
|
class Adapter
|
||||||
|
@ -67,16 +69,25 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(local, remote)
|
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
|
# Create the parent directories if they does not exist (naive mkdir -p)
|
||||||
if !@server.list("/").any? { |f| f.start_with?(parent) }
|
fullpath.descend do |path|
|
||||||
@server.mkdir(parent)
|
if @server.list(path.to_s).empty?
|
||||||
|
@server.mkdir(path.to_s)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Upload the file
|
# Upload the file
|
||||||
@server.putbinaryfile(local, remote)
|
@server.putbinaryfile(local, remote)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def pwd
|
||||||
|
@pwd ||= @server.pwd
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue