Method: RGen::Util::FileCacheMap#load_data
- Defined in:
- lib/rgen/util/file_cache_map.rb
#load_data(key_path, options = {}) ⇒ Object
load data associated with file key_path returns :invalid in case either the associated file or the cache file has changed
options:
:invalidation_reasons:
an array which will receive symbols indicating why the cache is invalid:
:no_cachefile, :cachefile_corrupted, :keyfile_changed
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rgen/util/file_cache_map.rb', line 35 def load_data(key_path, ={}) reasons = [:invalidation_reasons] || [] cf = cache_file(key_path) result = nil begin File.open(cf, "rb") do |f| header = f.read(41) if !header reasons << :cachefile_corrupted return :invalid end checksum = header[0..39] data = f.read if calc_sha1(data) == checksum if calc_sha1_keydata(key_path) == data[0..39] result = data[41..-1] else reasons << :keyfile_changed result = :invalid end else reasons << :cachefile_corrupted result = :invalid end end rescue Errno::ENOENT reasons << :no_cachefile result = :invalid end result end |