From 65996b5887ac6e4b669e9460b8e2a4fbc7171984 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Wed, 9 Sep 2015 14:00:26 +0800 Subject: [PATCH] use json to cache descriptions We need to use `atomic_write` when saving the cache. And it seems that CSV module doesn't support dump, so let's use JSON instead. --- Library/Homebrew/descriptions.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index 5f7f44c4d4..09ea7ed561 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -1,9 +1,8 @@ require "formula" require "formula_versions" -require "csv" class Descriptions - CACHE_FILE = HOMEBREW_CACHE + "desc_cache" + CACHE_FILE = HOMEBREW_CACHE + "desc_cache.json" def self.cache @cache || self.load_cache @@ -13,9 +12,7 @@ class Descriptions # return nil. def self.load_cache if CACHE_FILE.exist? - @cache = {} - CSV.foreach(CACHE_FILE) { |name, desc| @cache[name] = desc } - @cache + @cache = Utils::JSON.load(CACHE_FILE.read) end end @@ -23,11 +20,7 @@ class Descriptions # directory. def self.save_cache HOMEBREW_CACHE.mkpath - CSV.open(CACHE_FILE, 'w') do |csv| - @cache.each do |name, desc| - csv << [name, desc] - end - end + CACHE_FILE.atomic_write Utils::JSON.dump(@cache) end # Create a hash mapping all formulae to their descriptions;