Method: Inspec::TarProvider#extract

Defined in:
lib/inspec/file_provider.rb

#extract(destination_path = '.') ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/inspec/file_provider.rb', line 169

def extract(destination_path = '.')
  FileUtils.mkdir_p(destination_path)

  walk_tar(@path) do |files|
    files.each do |file|
      next unless @files.include?(file.full_name)
      final_path = File.join(destination_path, file.full_name)

      # This removes the top level directory (and any other files) to ensure
      # extracted files do not conflict.
      FileUtils.remove_entry(final_path) if File.exist?(final_path)

      FileUtils.mkdir_p(File.dirname(final_path))
      File.open(final_path, 'wb') { |f| f.write(file.read) }
    end
  end
end