Skip to content

Commit

Permalink
Sometimes YAML files get corrupted.
Browse files Browse the repository at this point in the history
Sanity check results from YAML.load_file and destroy
file if it is invalid.
  • Loading branch information
Jason Ketterman authored and Charles Jolley committed Jan 14, 2010
1 parent b1d9187 commit 2094fe7
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/sproutcore/models/target.rb
Expand Up @@ -332,15 +332,15 @@ def _write_file_attr_cache
def file_attr(attr_name, path, &block)

# read cache from disk if needed
if @file_attr_cache.nil?
if File.exists?(file_attr_cache_path)
require 'yaml'
@file_attr_cache = YAML.load File.read(file_attr_cache_path)
else
@file_attr_cache = {}
end
if @file_attr_cache.nil? && File.exists?(file_attr_cache_path)
require 'yaml'
@file_attr_cache = YAML.load_file file_attr_cache_path

# Sometimes the file is corrupted, in this case, clear the cache
File.delete file_attr_cache_path unless @file_attr_cache
end

@file_attr_cache ||= {}

path_root = (@file_attr_cache[path] ||= {})
attr_info = (path_root[attr_name.to_s] ||= {})
attr_mtime = attr_info['mtime'].to_i
Expand Down

0 comments on commit 2094fe7

Please sign in to comment.