Method: Inspec::Profile.copy_deps_into_cache

Defined in:
lib/inspec/profile.rb

.copy_deps_into_cache(file_provider, opts) ⇒ Object

Check if the profile contains a vendored cache, move content into global cache TODO: use relative file provider TODO: use source reader for Cache as well



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/inspec/profile.rb', line 32

def self.copy_deps_into_cache(file_provider, opts)
  # filter content
  cache = file_provider.files.find_all do |entry|
    entry.start_with?('vendor')
  end
  content = Hash[cache.map { |x| [x, file_provider.read(x)] }]
  keys = content.keys
  keys.each do |key|
    next if content[key].nil?
    # remove prefix
    rel = Pathname.new(key).relative_path_from(Pathname.new('vendor')).to_s
    tar = Pathname.new(opts[:cache].path).join(rel)

    FileUtils.mkdir_p tar.dirname.to_s
    Inspec::Log.debug "Copy #{tar} to cache directory"
    File.write(tar.to_s, content[key].force_encoding('UTF-8'))
  end
end