class Mixlib::Archive

Constants

VERSION

Attributes

archiver[R]
extractor[R]

Public Class Methods

archive_directory(path, archive, gzip: false, format: :tar, compression: :none) click to toggle source
# 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
new(archive, empty: false) click to toggle source
# 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_relative "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

Public Instance Methods

create(files = [], gzip: false) click to toggle source
# File lib/mixlib/archive.rb, line 38
def create(files = [], gzip: false)
  archiver.create(files, gzip: gzip)
end
extract(destination, perms: true, ignore: []) click to toggle source
# 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

Private Instance Methods

create_and_empty(destination) click to toggle source
# File lib/mixlib/archive.rb, line 56
def create_and_empty(destination)
  FileUtils.mkdir_p(destination)
  if @empty
    Dir.foreach(destination) do |entry|
      next if entry == "." || entry == ".."

      FileUtils.remove_entry_secure(File.join(destination, entry))
    end
  end
end
path_separator() click to toggle source
# File lib/mixlib/archive.rb, line 52
def path_separator
  File::SEPARATOR
end