Permalink
Browse files

Avoid closing the input stream on capture with sudo in the command.

  • Loading branch information...
1 parent 2d217a8 commit 7a5df72aee12ebe69f59f42c70bed9f7919a94e7 @dylanahsmith dylanahsmith committed Sep 14, 2012
Showing with 13 additions and 2 deletions.
  1. +2 −2 lib/capistrano/configuration/actions/inspect.rb
  2. +11 −0 test/configuration/actions/inspect_test.rb
View
4 lib/capistrano/configuration/actions/inspect.rb
@@ -20,7 +20,7 @@ module Inspect
# stream "tail -f #{shared_path}/log/fastcgi.crash.log"
# end
def stream(command, options={})
- invoke_command(command, options.merge(:eof => true)) do |ch, stream, out|
+ invoke_command(command, options.merge(:eof => !command.include?(sudo))) do |ch, stream, out|
puts out if stream == :out
warn "[err :: #{ch[:server]}] #{out}" if stream == :err
end
@@ -31,7 +31,7 @@ def stream(command, options={})
# string. The command is invoked via #invoke_command.
def capture(command, options={})
output = ""
- invoke_command(command, options.merge(:once => true, :eof => true)) do |ch, stream, data|
+ invoke_command(command, options.merge(:once => true, :eof => !command.include?(sudo))) do |ch, stream, data|
case stream
when :out then output << data
when :err then warn "[err :: #{ch[:server]}] #{data}"
View
11 test/configuration/actions/inspect_test.rb
@@ -9,13 +9,19 @@ class MockConfig
def setup
@config = MockConfig.new
@config.stubs(:logger).returns(stub_everything)
+ @config.stubs(:sudo).returns('sudo')
end
def test_stream_should_pass_options_through_to_run
@config.expects(:invoke_command).with("tail -f foo.log", :once => true, :eof => true)
@config.stream("tail -f foo.log", :once => true)
end
+ def test_stream_with_sudo_should_avoid_closing_stdin
+ @config.expects(:invoke_command).with("sudo tail -f foo.log", :once => true, :eof => false)
+ @config.stream("sudo tail -f foo.log", :once => true)
+ end
+
def test_stream_should_emit_stdout_via_puts
@config.expects(:invoke_command).yields(mock("channel"), :out, "something streamed")
@config.expects(:puts).with("something streamed")
@@ -37,6 +43,11 @@ def test_capture_should_pass_options_merged_with_once_to_run
@config.capture("hostname", :foo => "bar")
end
+ def test_capture_with_sudo_should_avoid_closing_stdin
+ @config.expects(:invoke_command).with("sudo hostname", :foo => "bar", :once => true, :eof => false)
+ @config.capture("sudo hostname", :foo => "bar")
+ end
+
def test_capture_with_stderr_should_emit_stderr_via_warn
ch = mock("channel")
ch.expects(:[]).with(:server).returns(server("capistrano"))

0 comments on commit 7a5df72

Please sign in to comment.