Class: TerraspaceBundler::Extract::Tar
- Inherits:
-
Object
- Object
- TerraspaceBundler::Extract::Tar
- Defined in:
- lib/terraspace_bundler/extract/tar.rb
Class Method Summary collapse
-
.extract(tar_gz_archive, destination) ⇒ Object
tar_gz_archive = ‘/tmp/terraspace/bundler/stage/s3-us-west-2.amazonaws.com/demo-terraform-test/modules/example-module.tgz’ destination = ‘/tmp/terraspace/where/extract/to’.
Class Method Details
.extract(tar_gz_archive, destination) ⇒ Object
tar_gz_archive = ‘/tmp/terraspace/bundler/stage/s3-us-west-2.amazonaws.com/demo-terraform-test/modules/example-module.tgz’ destination = ‘/tmp/terraspace/where/extract/to’
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/terraspace_bundler/extract/tar.rb', line 10 def self.extract(tar_gz_archive, destination) reader = Zlib::GzipReader.open(tar_gz_archive) Gem::Package::TarReader.new(reader) do |tar| dest = nil tar.each do |entry| dest ||= File.join destination, entry.full_name if entry.directory? FileUtils.rm_rf dest unless File.directory? dest FileUtils.mkdir_p dest, :mode => entry.header.mode, :verbose => false elsif entry.file? FileUtils.rm_rf dest unless File.file? dest File.open dest, "wb" do |f| f.print entry.read end FileUtils.chmod entry.header.mode, dest, :verbose => false elsif entry.header.typeflag == '2' #Symlink! File.symlink entry.header.linkname, dest end dest = nil end end end |