Skip to content
This repository

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

Merged
merged 1 commit into from over 1 year ago

2 participants

Dylan Thacker-Smith Roy Liu
Dylan Thacker-Smith

This was another corner case from closing the input stream that was brought up in issue #253.

This should have been done along with pull request #254.

Roy Liu carsomyr merged commit 7a5df72 into from
Roy Liu carsomyr closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
4  lib/capistrano/configuration/actions/inspect.rb
@@ -20,7 +20,7 @@ module Inspect
20 20
         #     stream "tail -f #{shared_path}/log/fastcgi.crash.log"
21 21
         #   end
22 22
         def stream(command, options={})
23  
-          invoke_command(command, options.merge(:eof => true)) do |ch, stream, out|
  23
+          invoke_command(command, options.merge(:eof => !command.include?(sudo))) do |ch, stream, out|
24 24
             puts out if stream == :out
25 25
             warn "[err :: #{ch[:server]}] #{out}" if stream == :err
26 26
           end
@@ -31,7 +31,7 @@ def stream(command, options={})
31 31
         # string. The command is invoked via #invoke_command.
32 32
         def capture(command, options={})
33 33
           output = ""
34  
-          invoke_command(command, options.merge(:once => true, :eof => true)) do |ch, stream, data|
  34
+          invoke_command(command, options.merge(:once => true, :eof => !command.include?(sudo))) do |ch, stream, data|
35 35
             case stream
36 36
             when :out then output << data
37 37
             when :err then warn "[err :: #{ch[:server]}] #{data}"
11  test/configuration/actions/inspect_test.rb
@@ -9,6 +9,7 @@ class MockConfig
9 9
   def setup
10 10
     @config = MockConfig.new
11 11
     @config.stubs(:logger).returns(stub_everything)
  12
+    @config.stubs(:sudo).returns('sudo')
12 13
   end
13 14
 
14 15
   def test_stream_should_pass_options_through_to_run
@@ -16,6 +17,11 @@ def test_stream_should_pass_options_through_to_run
16 17
     @config.stream("tail -f foo.log", :once => true)
17 18
   end
18 19
 
  20
+  def test_stream_with_sudo_should_avoid_closing_stdin
  21
+    @config.expects(:invoke_command).with("sudo tail -f foo.log", :once => true, :eof => false)
  22
+    @config.stream("sudo tail -f foo.log", :once => true)
  23
+  end
  24
+
19 25
   def test_stream_should_emit_stdout_via_puts
20 26
     @config.expects(:invoke_command).yields(mock("channel"), :out, "something streamed")
21 27
     @config.expects(:puts).with("something streamed")
@@ -37,6 +43,11 @@ def test_capture_should_pass_options_merged_with_once_to_run
37 43
     @config.capture("hostname", :foo => "bar")
38 44
   end
39 45
 
  46
+  def test_capture_with_sudo_should_avoid_closing_stdin
  47
+    @config.expects(:invoke_command).with("sudo hostname", :foo => "bar", :once => true, :eof => false)
  48
+    @config.capture("sudo hostname", :foo => "bar")
  49
+  end
  50
+
40 51
   def test_capture_with_stderr_should_emit_stderr_via_warn
41 52
     ch = mock("channel")
42 53
     ch.expects(:[]).with(:server).returns(server("capistrano"))
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.