Skip to content

Commit c11c6cd

Browse files
authored
Merge pull request #22553 from Homebrew/trust-fixes
Skip untrusted cleanup formulae
2 parents 182fd8e + 08c9669 commit c11c6cd

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

Library/Homebrew/cleanup.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def stale_formula?(pathname, scrub)
154154

155155
formula = begin
156156
Formulary.from_rack(HOMEBREW_CELLAR/formula_name)
157+
rescue Homebrew::UntrustedTapError
158+
opoo "Skipping #{formula_name}: tap formula is not trusted"
159+
nil
157160
rescue FormulaUnavailableError, TapFormulaAmbiguityError
158161
nil
159162
end
@@ -162,6 +165,9 @@ def stale_formula?(pathname, scrub)
162165
if formula.blank? && formula_name.delete_suffix!("_bottle_manifest")
163166
formula = begin
164167
Formulary.from_rack(HOMEBREW_CELLAR/formula_name)
168+
rescue Homebrew::UntrustedTapError
169+
opoo "Skipping #{formula_name}: tap formula is not trusted"
170+
nil
165171
rescue FormulaUnavailableError, TapFormulaAmbiguityError
166172
nil
167173
end

Library/Homebrew/test/cleanup_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@
6969
expect(lock_file).to exist
7070
end
7171

72+
it "doesn't load untrusted installed formulae while cleaning the cache" do
73+
cache_file = HOMEBREW_CACHE/"untrusted--1.0"
74+
cache_file.write "cached"
75+
(HOMEBREW_CELLAR/"untrusted/1.0").mkpath
76+
77+
expect(Formulary).to receive(:from_rack).with(HOMEBREW_CELLAR/"untrusted")
78+
.and_raise(Homebrew::UntrustedTapError)
79+
80+
expect { cleanup.cleanup_cache([{ path: cache_file, type: nil }]) }
81+
.to output(/Skipping untrusted: tap formula is not trusted/).to_stderr
82+
expect(cache_file).to exist
83+
end
84+
7285
context "when it can't remove a keg" do
7386
let(:formula_zero_dot_one) { Class.new(Testball) { version "0.1" }.new }
7487
let(:formula_zero_dot_two) { Class.new(Testball) { version "0.2" }.new }

0 commit comments

Comments
 (0)