From bda132bb5423fd91a2a3df5584c57074549147ac Mon Sep 17 00:00:00 2001 From: Martin Vidner Date: Wed, 30 Aug 2017 14:17:27 +0200 Subject: [PATCH] Cache the bash_output path re-creating the path is the most expensive thing after actually running the commands --- library/systemd/src/lib/yast2/systemctl.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/systemd/src/lib/yast2/systemctl.rb b/library/systemd/src/lib/yast2/systemctl.rb index 41973e5e4..11c5367d1 100644 --- a/library/systemd/src/lib/yast2/systemctl.rb +++ b/library/systemd/src/lib/yast2/systemctl.rb @@ -24,6 +24,8 @@ module Systemctl TIMEOUT = 30 # seconds class << self + BASH_SCR_PATH = Yast::Path.new(".target.bash_output") + # @param command [String] # @return [#command,#stdout,#stderr,#exit] # @raise [SystemctlError] if it times out @@ -31,7 +33,7 @@ def execute(command) log.info("systemctl #{command}") command = SYSTEMCTL + command log.debug "Executing `systemctl` command: #{command}" - result = timeout(TIMEOUT) { SCR.Execute(Path.new(".target.bash_output"), command) } + result = timeout(TIMEOUT) { SCR.Execute(BASH_SCR_PATH, command) } OpenStruct.new(result.merge!(command: command)) rescue Timeout::Error raise SystemctlError, "Timeout #{TIMEOUT} seconds: #{command}"