def get_filename(filename)
if filename =~ /([^\/]+)\/(.+)$/
segment = $1
else
raise "get_filename: Cannot determine segment/filename for incoming filename #{filename}"
end
raise "No such segment #{segment} in cookbook #{@cookbook_name}" unless @manifest[segment]
found_manifest_record = @manifest[segment].find {|manifest_record| manifest_record[:path] == filename }
raise "No such file #{filename} in #{@cookbook_name}" unless found_manifest_record
cache_filename = File.join("cookbooks", @cookbook_name, found_manifest_record['path'])
validate_cached_copy(cache_filename)
current_checksum = nil
if Chef::FileCache.has_key?(cache_filename)
current_checksum = Chef::CookbookVersion.checksum_cookbook_file(Chef::FileCache.load(cache_filename, false))
end
if current_checksum != found_manifest_record['checksum']
raw_file = @rest.get_rest(found_manifest_record[:url], true)
Chef::Log.debug("Storing updated #{cache_filename} in the cache.")
Chef::FileCache.move_to(raw_file.path, cache_filename)
else
Chef::Log.debug("Not storing #{cache_filename}, as the cache is up to date.")
end
full_path_cache_filename = Chef::FileCache.load(cache_filename, false)
full_path_cache_filename
end