Skip to content

Commit

Permalink
Merge pull request #16977 from Homebrew/cleanup-fixes
Browse files Browse the repository at this point in the history
cleanup: fix various cases where cache wasn't being removed properly
  • Loading branch information
Bo98 authored Mar 31, 2024
2 parents 3e8dc3c + 58de9e0 commit da456da
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
12 changes: 10 additions & 2 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ def stale_formula?(pathname, scrub)
nil
end

if formula.blank? && formula_name.delete_suffix!("_bottle_manifest")
formula = begin
Formulary.from_rack(HOMEBREW_CELLAR/formula_name)
rescue FormulaUnavailableError, TapFormulaAmbiguityError
nil
end
end

return false if formula.blank?

resource_name = basename_str[/\A.*?--(.*?)--?(?:#{Regexp.escape(version.to_s)})/, 1]
Expand All @@ -143,7 +151,7 @@ def stale_formula?(pathname, scrub)
return true unless patch_hashes&.include?(Checksum.new(version.to_s))
elsif resource_name && (resource_version = formula.stable&.resources&.dig(resource_name)&.version)
return true if resource_version != version
elsif formula.version > version
elsif (formula.latest_version_installed? && formula.version != version) || formula.version > version
return true
end

Expand Down Expand Up @@ -328,7 +336,7 @@ def unremovable_kegs
def cleanup_formula(formula, quiet: false, ds_store: true, cache_db: true)
formula.eligible_kegs_for_cleanup(quiet:)
.each(&method(:cleanup_keg))
cleanup_cache(Pathname.glob(cache/"#{formula.name}--*").map { |path| { path:, type: nil } })
cleanup_cache(Pathname.glob(cache/"#{formula.name}{_bottle_manifest,}--*").map { |path| { path:, type: nil } })
rm_ds_store([formula.rack]) if ds_store
cleanup_cache_db(formula.rack) if cache_db
cleanup_lockfiles(FormulaLock.new(formula.name).path)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def extname

extend Forwardable

attr_reader :name, :resource, :cellar, :rebuild
attr_reader :name, :resource, :tag, :cellar, :rebuild

def_delegators :resource, :url, :verify_download_integrity
def_delegators :resource, :cached_download
Expand Down
11 changes: 5 additions & 6 deletions Library/Homebrew/utils/bottles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,15 @@ def built_as?(formula)
end

def file_outdated?(formula, file)
file = file.resolved_path

filename = file.basename.to_s
return false if formula.bottle.blank?

bottle_ext, bottle_tag, = extname_tag_rebuild(filename)
return false if bottle_ext.blank?
return false if bottle_tag != tag.to_s

bottle_url_ext, = extname_tag_rebuild(formula.bottle.url)
_, bottle_tag, bottle_rebuild = extname_tag_rebuild(filename)
return false if bottle_tag.blank?

bottle_ext && bottle_url_ext && bottle_ext != bottle_url_ext
bottle_tag != formula.bottle.tag.to_s || bottle_rebuild.to_i != formula.bottle.rebuild
end

def extname_tag_rebuild(filename)
Expand Down

0 comments on commit da456da

Please sign in to comment.