Descriptions.cache_formulae: secure formulae loading

This commit is contained in:
Xu Cheng 2015-09-09 13:55:19 +08:00
parent 71be19235f
commit c5536e1e08

View File

@ -1,4 +1,5 @@
require "formula" require "formula"
require "formula_versions"
require "csv" require "csv"
class Descriptions class Descriptions
@ -92,7 +93,13 @@ class Descriptions
# cache. Save the updated cache to disk, unless explicitly told not to. # cache. Save the updated cache to disk, unless explicitly told not to.
def self.cache_formulae(formula_names, options = { :save => true }) def self.cache_formulae(formula_names, options = { :save => true })
if self.cache if self.cache
formula_names.each { |name| @cache[name] = Formula[name].desc } formula_names.each do |name|
begin
desc = Formulary.factory(name).desc
rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS
end
@cache[name] = desc
end
self.save_cache if options[:save] self.save_cache if options[:save]
end end
end end