Class: Mixlib::Archive

Inherits:
Object
  • Object
show all
Defined in:
lib/mixlib/archive.rb,
lib/mixlib/archive/tar.rb,
lib/mixlib/archive/version.rb,
lib/mixlib/archive/lib_archive.rb

Defined Under Namespace

Classes: LibArchive, Log, Tar, TarError

Constant Summary collapse

VERSION =
"0.4.20".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(archive, empty: false) ⇒ Archive

Returns a new instance of Archive.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mixlib/archive.rb', line 18

def initialize(archive, empty: false)
  @empty = empty

  archive = File.expand_path(archive)
  begin
    # we prefer to use libarchive, which supports a great big pile o' stuff
    require "mixlib/archive/lib_archive"
    @archiver = Mixlib::Archive::LibArchive.new(archive)
  rescue LoadError
    # but if we can't use that, we'll fall back to ruby's native tar implementation
    @archiver = Mixlib::Archive::Tar.new(archive)
  end
end

Instance Attribute Details

#archiverObject (readonly) Also known as: extractor

Returns the value of attribute archiver.



10
11
12
# File 'lib/mixlib/archive.rb', line 10

def archiver
  @archiver
end

Class Method Details

.archive_directory(path, archive, gzip: false, format: :tar, compression: :none) ⇒ Object



13
14
15
16
# File 'lib/mixlib/archive.rb', line 13

def self.archive_directory(path, archive, gzip: false, format: :tar, compression: :none)
  targets = Find.find(path).collect { |fn| fn }
  new(archive).create(targets, gzip: gzip)
end

Instance Method Details

#create(files = [], gzip: false) ⇒ Object



38
39
40
# File 'lib/mixlib/archive.rb', line 38

def create(files = [], gzip: false)
  archiver.create(files, gzip: gzip)
end

#extract(destination, perms: true, ignore: []) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/mixlib/archive.rb', line 42

def extract(destination, perms: true, ignore: [])
  ignore = [/^\.$/, /\.{2}#{path_separator}/] + Array(ignore)

  create_and_empty(destination)

  archiver.extract(destination, perms: perms, ignore: ignore)
end