Method: CacheManager#get_target_cache

Defined in:
lib/kcache.rb

#get_target_cache(target, target_md5) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/kcache.rb', line 278

def get_target_cache(target, target_md5)

    dependency_start_time = Time.now

    target_cache_dirs = Dir.glob(get_cache_root + "/" + target.name + "-" + target_md5 + "-*")

    hit_results = []

    target_cache_dirs.each do |target_cache_dir|
        unless File.exist? target_cache_dir + "/" + FILE_NAME_PRODUCT
            puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
            next
        end
        unless File.exist? target_cache_dir + "/" + FILE_NAME_CONTEXT
            puts "<ERROR> #{target.name} target cache dir missed files: #{target_cache_dir}"
            next
        end

        target_context = YAML.load(File.read(target_cache_dir + "/" + FILE_NAME_CONTEXT))

        if target_context[:target_md5] != target_md5 or target_context[:product_md5] != get_file_md5(target_cache_dir + "/" + FILE_NAME_PRODUCT)
            command = "rm -rf \"#{target_cache_dir}\""
            raise unless system command
            puts "<ERROR> #{target.name} target md5 does not match:  #{target_cache_dir}"
        end

        dependency_exit = true
        
        if target_context[:dependency_files_md5] 
            target_context[:dependency_files_md5].each do | item |
                dependency_file = item[0]
                dependency_md5 = item[1]
                unless File.exist? dependency_file
                    puts "<WARNING> #{target.name} dependency file miss: #{dependency_file}"
                    dependency_exit = false
                    break
                end
                unless get_file_md5(dependency_file) == dependency_md5
                    puts "<WARNING> #{target.name} dependency file md5 does not match: #{dependency_file}"
                    dependency_exit = false
                    break
                end
            end
        end

        if dependency_exit
            hit_results.push target_cache_dir
        end
    end

    return hit_results

end