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

View File

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

View File

@ -148,7 +148,7 @@ describe "download strategies", :cask do
"DBw2KdR24q9t1wfjS9LUzelf5TWk6ojj8p9%2FHjl%2Fi%2FVCXN",
"N4o1mW%2FMayy2tTY1qcC%2FTmqI1ulZS8SNuaSgr9Iys9oDF1%2",
"BPK%2B4Sg==",
].join("")
].join
end
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
expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join(""))
expected = Regexp.compile(<<~EOS.lines.map(&:chomp).join)
(?m)
Warning:
.*

View File

@ -134,7 +134,7 @@ describe Hbc::Pkg, :cask do
<string>#{volume}</string>
<key>paths</key>
<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>
</plist>

View File

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

View File

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