Fix cross-host write error and closing "}" truncation bug.

This commit is contained in:
junyi 2026-09-04 11:55:04 +00:00
parent f75bd8bbf0
commit 188231bc75
1 changed files with 17 additions and 5 deletions

View File

@ -34,13 +34,24 @@ namespace :create_site do
auto_update_infos("Writing via safe stream...") auto_update_infos("Writing via safe stream...")
ssh.open_channel do |channel| ssh.open_channel do |channel|
channel.exec("sudo -S sh -c 'cat > #{site_construct.nginx_file}'") do |ch, success| channel.exec("sudo -S sh -c 'cat > #{site_construct.nginx_file}'") do |ch, success|
content_sent = false
send_content_once = lambda do
unless content_sent
content_sent = true
ch.send_data(nginx_file_content)
ch.eof!
end
end
ch.on_extended_data do |c, type, data| ch.on_extended_data do |c, type, data|
if data =~ /password/i if data =~ /password/i
c.send_data("#{@password}\n") c.send_data("#{@password}\n")
end end
send_content_once.call
end end
ch.send_data(nginx_file_content) Thread.new {
ch.eof! sleep 2
send_content_once.call
}
end end
end end
ssh.loop ssh.loop
@ -50,7 +61,8 @@ namespace :create_site do
def exec_command_by_user(session,command) def exec_command_by_user(session,command)
output = session.exec!(command) output = session.exec!(command)
return output[0...-1].gsub(/^\n[\n]+/,'') output = output[0...-1] if output.end_with?("\n")
return output.gsub(/^\n[\n]+/,'')
end end
def exec_ssh_command_by_sudo(session,command) def exec_ssh_command_by_sudo(session,command)
output = session.exec!("echo '#{@password}' | sudo -S #{command}") output = session.exec!("echo '#{@password}' | sudo -S #{command}")