From 783927c59b17bc58ce6e04f131a2f6a7d2aed5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Thu, 9 May 2024 21:12:04 +0800 Subject: [PATCH] Fix bug. --- lib/tasks/detect_sites.rake | 6 ++-- lib/tasks/exec_command.rake | 60 ++++++++++++------------------------- 2 files changed, 23 insertions(+), 43 deletions(-) diff --git a/lib/tasks/detect_sites.rake b/lib/tasks/detect_sites.rake index 0dbfcf3..7ec5049 100644 --- a/lib/tasks/detect_sites.rake +++ b/lib/tasks/detect_sites.rake @@ -147,12 +147,14 @@ namespace :create_site do crt_file_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{crt_file_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n") FileUtils.mkdir_p(File.dirname(cert_file_store_path)) unless Dir.exist?(File.dirname(cert_file_store_path)) File.open(cert_file_store_path,'w+'){|f| f.write(crt_file_content)} + site_cert["cert_file"] = File.basename(cert_file_store_path) site_cert.cert_file.retrieve_from_store!(File.basename(cert_file_store_path)) - private_key_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(private_key_path)}" + private_key_store_path = "public/#{site_cert.private_key.store_dir}/#{File.basename(private_key_path)}" private_key_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{private_key_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n") FileUtils.mkdir_p(File.dirname(private_key_store_path)) unless Dir.exist?(File.dirname(private_key_store_path)) File.open(private_key_store_path,'w+'){|f| f.write(private_key_content)} - site_cert.private_key.retrieve_from_store!(File.basename(private_key_path)) + site_cert["private_key"] = File.basename(private_key_store_path) + site_cert.private_key.retrieve_from_store!(File.basename(private_key_store_path)) site_cert.source_paths = [crt_file_path,private_key_path] site_cert.is_certbot = private_key_path.include?("letsencrypt") site_cert.save diff --git a/lib/tasks/exec_command.rake b/lib/tasks/exec_command.rake index aad72f4..b6849cf 100644 --- a/lib/tasks/exec_command.rake +++ b/lib/tasks/exec_command.rake @@ -262,57 +262,35 @@ namespace :exec_commands do channel.send_data "#{@password}\n" else print data_str unless @no_stdout - data_str.gsub!("\r\n", "\n") - rm_idx = data_str.index("\r") - if rm_idx.nil? - @remove_last_line = false - else - @remove_last_line = (outputs.count > 0 && data_str[0...rm_idx].exclude?("\n")) - end - data_str.gsub!(/.*\r/, '') + data_str.gsub!(/\r\n/, "\n") next if data_str.length == 0 - if data_str.include?("\n") || outputs.empty? - output_lines = data_str.split("\n") - first_output = output_lines[0] - if first_output - if @remove_last_line - outputs = outputs[1..-1] - outputs = [] if outputs.nil? - end - if outputs.count != 0 - outputs[-1] += first_output - else - outputs << first_output + output_lines = data_str.split("\n", -1) + first_output = output_lines[0] + if first_output + if outputs.count != 0 + outputs[-1] += first_output + @remove_last_line = false + outputs[-1] = outputs[-1].sub(/(.+)\r(.+)/) do |s| + @remove_last_line = true + first_output = $2 end + else + outputs << first_output end + if update_outputs + update_thread_infos_for_exec(first_output,true) if @flag + update_infos_for_exec(first_output,true) + end + @remove_last_line = false new_arr = output_lines[1..-1] - new_arr = [] if new_arr.nil? - if data_str[-1] == "\n" - new_arr << "" + new_arr = new_arr.map do |output_line| + output_line = output_line.sub(/(.+)\r(.+)/, '\2') end outputs += new_arr if update_outputs - if first_output - update_thread_infos_for_exec(first_output,true) if @flag - update_infos_for_exec(first_output,true) - end update_thread_infos_for_exec(new_arr,false,true) if @flag update_infos_for_exec(new_arr,false,true) end - else - if @remove_last_line - outputs = outputs[1..-1] - outputs = [] if outputs.nil? - end - if outputs.count == 0 - outputs.push(data_str) - else - outputs[-1] += (data_str rescue "") - end - if update_outputs - update_thread_infos_for_exec(data_str,true) if @flag - update_infos_for_exec(data_str,true) - end end end end