Merge pull request #4342 from reitermarkus/sudo-sorry-try-again

Fix `sudo` “Sorry, try again.” delay.
This commit is contained in:
Markus Reiter 2018-06-15 14:08:08 +02:00 committed by GitHub
commit 32fa773cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 24 deletions

View File

@ -25,11 +25,11 @@ module Hbc
each_output_line do |type, line| each_output_line do |type, line|
case type case type
when :stdout when :stdout
puts line.chomp if print_stdout?
processed_output[:stdout] << line processed_output[:stdout] << line
ohai line.chomp if print_stdout?
when :stderr when :stderr
$stderr.puts Formatter.error(line.chomp) if print_stderr?
processed_output[:stderr] << line processed_output[:stderr] << line
ohai line.chomp if print_stderr?
end end
end end
@ -100,17 +100,23 @@ module Hbc
def each_line_from(sources) def each_line_from(sources)
loop do loop do
readable_sources = IO.select(sources)[0] readable_sources, = IO.select(sources)
readable_sources.delete_if(&:eof?).first(1).each do |source|
type = ((source == sources[0]) ? :stdout : :stderr) readable_sources = readable_sources.reject(&:eof?)
break if readable_sources.empty?
readable_sources.each do |source|
begin begin
yield(type, source.readline_nonblock || "") line = source.readline_nonblock || ""
type = (source == sources[0]) ? :stdout : :stderr
yield(type, line)
rescue IO::WaitReadable, EOFError rescue IO::WaitReadable, EOFError
next next
end end
end end
break if readable_sources.empty?
end end
sources.each(&:close_read) sources.each(&:close_read)
end end

View File

@ -460,7 +460,7 @@ module RuboCop
when :str when :str
node.str_content node.str_content
when :dstr when :dstr
node.each_child_node(:str).map(&:str_content).join("") node.each_child_node(:str).map(&:str_content).join
when :const when :const
node.const_name node.const_name
when :sym when :sym

View File

@ -148,7 +148,7 @@ describe "download strategies", :cask do
"DBw2KdR24q9t1wfjS9LUzelf5TWk6ojj8p9%2FHjl%2Fi%2FVCXN", "DBw2KdR24q9t1wfjS9LUzelf5TWk6ojj8p9%2FHjl%2Fi%2FVCXN",
"N4o1mW%2FMayy2tTY1qcC%2FTmqI1ulZS8SNuaSgr9Iys9oDF1%2", "N4o1mW%2FMayy2tTY1qcC%2FTmqI1ulZS8SNuaSgr9Iys9oDF1%2",
"BPK%2B4Sg==", "BPK%2B4Sg==",
].join("") ].join
end end
describe "#tarball_path" do describe "#tarball_path" do

View File

@ -20,7 +20,7 @@ describe Hbc::DSL, :cask do
} }
it "prints a warning that it has encountered an unexpected method" do it "prints a warning that it has encountered an unexpected method" do
expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join("")) expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join)
(?m) (?m)
Warning: Warning:
.* .*

View File

@ -134,7 +134,7 @@ describe Hbc::Pkg, :cask do
<string>#{volume}</string> <string>#{volume}</string>
<key>paths</key> <key>paths</key>
<dict> <dict>
#{(pkg_files + pkg_directories).map { |f| "<key>#{f}</key><dict></dict>" }.join("")} #{(pkg_files + pkg_directories).map { |f| "<key>#{f}</key><dict></dict>" }.join}
</dict> </dict>
</dict> </dict>
</plist> </plist>

View File

@ -66,10 +66,10 @@ describe Hbc::SystemCommand, :cask do
describe "with default options" do describe "with default options" do
it "echoes only STDERR" do it "echoes only STDERR" do
expected = [2, 4, 6].map { |i| "==> #{i}\n" }.join("") expected = [2, 4, 6].map { |i| "#{i}\n" }.join
expect { expect {
described_class.run(command, options) described_class.run(command, options)
}.to output(expected).to_stdout }.to output(expected).to_stderr
end end
include_examples("it returns '1 2 3 4 5 6'") include_examples("it returns '1 2 3 4 5 6'")
@ -80,12 +80,10 @@ describe Hbc::SystemCommand, :cask do
options.merge!(print_stdout: true) options.merge!(print_stdout: true)
end end
it "echoes both STDOUT and STDERR" do it "echoes both STDOUT and STDERR", :focus do
(1..6).each do |i| expect { described_class.run(command, options) }
expect { .to output("1\n3\n5\n").to_stdout
described_class.run(command, options) .and output("2\n4\n6\n").to_stderr
}.to output(/==> #{ i }/).to_stdout
end
end end
include_examples("it returns '1 2 3 4 5 6'") include_examples("it returns '1 2 3 4 5 6'")
@ -111,7 +109,7 @@ describe Hbc::SystemCommand, :cask do
end end
it "echoes only STDOUT" do it "echoes only STDOUT" do
expected = [1, 3, 5].map { |i| "==> #{i}\n" }.join("") expected = [1, 3, 5].map { |i| "#{i}\n" }.join
expect { expect {
described_class.run(command, options) described_class.run(command, options)
}.to output(expected).to_stdout }.to output(expected).to_stdout

View File

@ -6,10 +6,12 @@ module Tty
end end
def width def width
width = `/bin/stty size 2>/dev/null`.split[1] @width ||= begin
width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero? width = `/bin/stty size 2>/dev/null`.split[1]
width ||= 80 width = `/usr/bin/tput cols 2>/dev/null`.split[0] if width.to_i.zero?
width.to_i width ||= 80
width.to_i
end
end end
def truncate(string) def truncate(string)