Revert "shebang: raise error if no rewriting"

This is causing failures when attempting to rewrite shebangs during the
cleanup stage of `brew install`.

See, for example, Homebrew/homebrew-core#94323,
Homebrew/homebrew-core#94321.

This reverts commit 7e6be5eb4474ed9eaa4b8e9a5a45e3340186840c.
This commit is contained in:
Carlo Cabrera 2022-02-02 20:44:03 +08:00
parent d36b61d74b
commit 2b60a99d4a
No known key found for this signature in database
GPG Key ID: C74D447FC549A1D0
2 changed files with 0 additions and 34 deletions

View File

@ -1,30 +0,0 @@
# typed: false
# frozen_string_literal: true
require "utils/shebang"
describe Utils::Shebang do
let(:file) { Tempfile.new("shebang") }
before do
file.write "#!/usr/bin/python"
file.flush
end
after { file.unlink }
describe "rewrite_shebang" do
it "rewrites a shebang" do
rewrite_info = Utils::Shebang::RewriteInfo.new(/^#!.*python$/, 25, "new_shebang")
described_class.rewrite_shebang rewrite_info, file
expect(File.read(file)).to eq "#!new_shebang"
end
it "raises an error if no rewriting occurs" do
rewrite_info = Utils::Shebang::RewriteInfo.new(/^#!.*perl$/, 25, "new_shebang")
expect {
described_class.rewrite_shebang rewrite_info, file
}.to raise_error("No matching files found to rewrite shebang")
end
end
end

View File

@ -34,17 +34,13 @@ module Utils
# @api public
sig { params(rewrite_info: RewriteInfo, paths: T::Array[T.any(String, Pathname)]).void }
def rewrite_shebang(rewrite_info, *paths)
found = T.let(false, T::Boolean)
paths.each do |f|
f = Pathname(f)
next unless f.file?
next unless rewrite_info.regex.match?(f.read(rewrite_info.max_length))
Utils::Inreplace.inreplace f.to_s, rewrite_info.regex, "#!#{rewrite_info.replacement}"
found = true
end
raise "No matching files found to rewrite shebang" unless found
end
end
end