push via sftp issue when file parent directory does not exist
Overcomes exception Net::SFTP::StatusException (2, "no such file") when using: "vagrant push" via sftp and a file parent directory does not exist. Function "upload" does not create the directory before uploading a file ('mkdir: true' seems to have no effect as zero directories are created while files are uploaded normally).
This commit is contained in:
parent
197a2d8799
commit
a27e7e106a
|
@ -106,6 +106,7 @@ module VagrantPlugins
|
|||
def initialize(*)
|
||||
require "net/sftp"
|
||||
super
|
||||
@dirs = []
|
||||
end
|
||||
|
||||
def default_port
|
||||
|
@ -120,7 +121,21 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def upload(local, remote)
|
||||
@server.upload!(local, remote, mkdir: true)
|
||||
dir = File.dirname(remote)
|
||||
|
||||
fullpath = Pathname.new(dir)
|
||||
fullpath.descend do |path|
|
||||
if !@dirs.include?(path.to_s)
|
||||
@dirs.push(path.to_s) # Cache visited directories in a list to avoid duplicate requests
|
||||
begin
|
||||
@server.mkdir!(path.to_s)
|
||||
rescue Net::SFTP::StatusException => e
|
||||
# Directory exists, skip...
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@server.upload!(local, remote)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue