Class: Packmule::Archiver::Tar

Inherits:
Object
  • Object
show all
Defined in:
lib/packmule/archiver/tar.rb

Overview

Tar

Class Method Summary collapse

Class Method Details

.create(options) ⇒ Object

Creates the tar file, like a BOSS!



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/packmule/archiver/tar.rb', line 17

def self.create(options)
  options = {:gzip => false, :bzip => false, :xz => false}.merge(options)
  filename = "#{options[:filename]}.tar" + (options[:gzip] ? '.gz' : (options[:bzip] ? '.bz2' : (options[:xz] ? '.xz' : '')))

  # Make sure it doesn't exist..
  if ::FileTest.exists? "./#{filename}"
    puts "#{filename} already exists, skipping"
    return false
  end

  if options[:gzip] == true
    # Tar and gzip like a boss
    `tar czf #{filename} -C #{options[:dir]} ./`
  elsif options[:bzip] == true
    # Bzippit
    `tar cfj #{filename} -C #{options[:dir]} ./`
  elsif options[:xz] == true
    `tar cf - -C #{options[:dir]} ./ | xz -zf - > #{filename}`
  else
    # Totally boss taring code, yo
    `tar cf #{filename} -C #{options[:dir]} ./`
  end

  if ::FileTest.exists? "./#{filename}"
    puts " - #{filename} created"
  end

  return true
end