From e8c71646c135668c44e2ff1d55b43d4ebcc436bc Mon Sep 17 00:00:00 2001 From: Ryan Rotter Date: Sun, 30 Jun 2024 17:00:35 -0400 Subject: [PATCH] description cache invalid if updated w/o EVAL_ALL When updating description cache, if eval_all not set, clear cache rather than leaving it out of date. This fixes an issue where, if a user sets `--eval-all` on the command line to run description searches, but HOMEBREW_EVAL_ALL isn't set in the environment the cache is never updated. --- Library/Homebrew/cache_store.rb | 8 ++++++++ Library/Homebrew/description_cache_store.rb | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cache_store.rb b/Library/Homebrew/cache_store.rb index 27e0bd0a84..04ea3471cb 100644 --- a/Library/Homebrew/cache_store.rb +++ b/Library/Homebrew/cache_store.rb @@ -68,6 +68,14 @@ class CacheStoreDatabase db.delete(key) end + # Deletes all content from the underlying database (if it already exists). + def clear! + return unless created? + + dirty! + db.clear + end + # Closes the underlying database (if it is created and open). def write_if_dirty! return unless dirty? diff --git a/Library/Homebrew/description_cache_store.rb b/Library/Homebrew/description_cache_store.rb index 178025f7d5..fe634b8dd3 100644 --- a/Library/Homebrew/description_cache_store.rb +++ b/Library/Homebrew/description_cache_store.rb @@ -41,7 +41,10 @@ class DescriptionCacheStore < CacheStore # @param report [Report] an update report generated by cmd/update.rb # @return [nil] def update_from_report!(report) - return unless Homebrew::EnvConfig.eval_all? + unless Homebrew::EnvConfig.eval_all? + database.clear! + return + end return populate_if_empty! if database.empty? return if report.empty? @@ -60,7 +63,10 @@ class DescriptionCacheStore < CacheStore # @param formula_names [Array] the formulae to update # @return [nil] def update_from_formula_names!(formula_names) - return unless Homebrew::EnvConfig.eval_all? + unless Homebrew::EnvConfig.eval_all? + database.clear! + return + end return populate_if_empty! if database.empty? formula_names.each do |name| @@ -108,7 +114,10 @@ class CaskDescriptionCacheStore < DescriptionCacheStore # @param report [Report] an update report generated by cmd/update.rb # @return [nil] def update_from_report!(report) - return unless Homebrew::EnvConfig.eval_all? + unless Homebrew::EnvConfig.eval_all? + database.clear! + return + end return populate_if_empty! if database.empty? return if report.empty? @@ -124,7 +133,10 @@ class CaskDescriptionCacheStore < DescriptionCacheStore # @param cask_tokens [Array] the casks to update # @return [nil] def update_from_cask_tokens!(cask_tokens) - return unless Homebrew::EnvConfig.eval_all? + unless Homebrew::EnvConfig.eval_all? + database.clear! + return + end return populate_if_empty! if database.empty? cask_tokens.each do |token|