Sha256: 9f121a954ae84cd3949e7e6712c0ea1794b43c305f49d173a9936a091af48170

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

require "mixlib/archive/tar"
require "mixlib/archive/version"
require "mixlib/log"

module Mixlib
  class Archive
    attr_reader :extractor

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

      archive = File.expand_path(archive)
      # for now we only support Tar format archives.
      @extractor = Mixlib::Archive::Tar.new(archive)
    end

    class Log
      extend Mixlib::Log
    end

    Log.level = :error

    def extract(destination, perms: true, ignore: [])
      create_and_empty(destination)

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

    private

    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mixlib-archive-0.2.0 lib/mixlib/archive.rb