Skip to content

Commit 50fa89e

Browse files
authored
Merge pull request #20298 from Homebrew/forbidden-fix
Fix handling of formula install blocks
2 parents 48459b2 + b2ffe7b commit 50fa89e

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

Library/Homebrew/install.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -336,24 +336,28 @@ def install_formulae(
336336
fi.download_queue = download_queue
337337
end
338338
end
339+
340+
valid_formula_installers = formula_installers.dup
341+
339342
begin
340343
[:prelude_fetch, :prelude, :fetch].each do |step|
341-
formula_installers.each do |fi|
344+
valid_formula_installers.select! do |fi|
342345
fi.public_send(step)
346+
true
347+
rescue CannotInstallFormulaError => e
348+
ofail e.message
349+
false
343350
rescue UnsatisfiedRequirements, DownloadError, ChecksumMismatchError => e
344351
ofail "#{fi.formula}: #{e}"
345-
next
352+
false
346353
end
347354
download_queue&.fetch
348-
rescue CannotInstallFormulaError => e
349-
ofail e.message
350-
next
351355
end
352356
ensure
353357
download_queue&.shutdown
354358
end
355359

356-
formula_installers.each do |fi|
360+
valid_formula_installers.each do |fi|
357361
install_formula(fi)
358362
Cleanup.install_formula_clean!(fi.formula)
359363
end

Library/Homebrew/test/cmd/install_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ def install
9595

9696
expect(HOMEBREW_CELLAR/"testball1/0.1/bin/test").to be_a_file
9797
end
98+
99+
it "refuses to install forbidden formulae", :integration_test do
100+
setup_test_formula "testball1"
101+
102+
expect { brew "install", "testball1", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball1" } }
103+
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout
104+
.and output(/testball1 was forbidden/).to_stderr
105+
.and be_a_failure
106+
expect(HOMEBREW_CELLAR/"testball1").not_to exist
107+
end
98108
end

Library/Homebrew/test/cmd/reinstall_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@
3434

3535
expect(foo_dir).to exist
3636
end
37+
38+
it "refuses to reinstall a forbidden formula", :integration_test do
39+
install_test_formula "testball"
40+
foo_dir = HOMEBREW_CELLAR/"testball/0.1/bin"
41+
expect(foo_dir).to exist
42+
FileUtils.rm_r(foo_dir)
43+
44+
expect { brew "reinstall", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
45+
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
46+
.and output(/testball was forbidden/).to_stderr
47+
.and be_a_failure
48+
49+
expect(foo_dir).not_to exist
50+
end
3751
end

Library/Homebrew/test/cmd/upgrade_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,15 @@
2828
expect(HOMEBREW_CELLAR/"testball/0.1").to be_a_directory
2929
expect(HOMEBREW_CELLAR/"testball/0.0.1").not_to exist
3030
end
31+
32+
it "refuses to upgrades a forbidden formula", :integration_test do
33+
setup_test_formula "testball"
34+
(HOMEBREW_CELLAR/"testball/0.0.1/foo").mkpath
35+
36+
expect { brew "upgrade", "testball", { "HOMEBREW_FORBIDDEN_FORMULAE" => "testball" } }
37+
.to not_to_output(%r{#{HOMEBREW_CELLAR}/testball/0\.1}o).to_stdout
38+
.and output(/testball was forbidden/).to_stderr
39+
.and be_a_failure
40+
expect(HOMEBREW_CELLAR/"testball/0.1").not_to exist
41+
end
3142
end

Library/Homebrew/upgrade.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,23 @@ def self.formula_installers(
9292
end
9393

9494
def self.upgrade_formulae(formula_installers, dry_run: false, verbose: false)
95+
valid_formula_installers = formula_installers.dup
96+
9597
unless dry_run
96-
formula_installers.each do |fi|
98+
valid_formula_installers.select! do |fi|
9799
fi.prelude
98100
fi.fetch
101+
true
99102
rescue CannotInstallFormulaError => e
100103
ofail e
104+
false
101105
rescue UnsatisfiedRequirements, DownloadError => e
102106
ofail "#{fi.formula.full_name}: #{e}"
107+
false
103108
end
104109
end
105110

106-
formula_installers.each do |fi|
111+
valid_formula_installers.each do |fi|
107112
upgrade_formula(fi, dry_run:, verbose:)
108113
Cleanup.install_formula_clean!(fi.formula, dry_run:)
109114
end

0 commit comments

Comments
 (0)