Sha256: 4842966129899b6e829876b4956f08e556ce3ace4cdb7158a5d5adbbbe9259d0

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 KB

Contents

require 'archive/tar/minitar'
require 'zlib'
require 'minimart/mirror/download_metadata'

module Minimart
  module Utils

    # Archive manages tarring, and gzipping files
    module Archive

      # Extract a tar.gz archive
      # @param [String] archive_file The path to the archive file
      # @param [String] destination The directory to unpack the archive to
      def self.extract_archive(archive_file, destination)
        tar = Zlib::GzipReader.new(File.open(archive_file, 'rb'))
        ::Archive::Tar::Minitar.unpack(tar, destination)
      end

      # Build a tar.tz archive from a directory
      # @param [Minimart::Cookbook] cookbook The cookbook to archive
      # @param [String] destination The path to store the tar.gz archive
      def self.pack_archive(cookbook, destination)
        Dir.mktmpdir do |tmp|
          Dir.chdir(tmp) do
            archive_dir = File.join(tmp, cookbook.name)
            FileUtils.mkdir_p(archive_dir)
            FileUtils.cp_r(File.join(cookbook.path, '.'), archive_dir)
            meta_file = File.join(archive_dir, Minimart::Mirror::DownloadMetadata::FILE_NAME)
            FileUtils.remove_entry(meta_file) if File.exists?(meta_file)

            tgz = Zlib::GzipWriter.new(File.open(destination, 'wb'))
            ::Archive::Tar::Minitar.pack(cookbook.name, tgz)
          end
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
minimart-1.2.5 lib/minimart/utils/archive.rb
minimart-1.2.4 lib/minimart/utils/archive.rb
minimart-1.2.3 lib/minimart/utils/archive.rb
minimart-1.2.0 lib/minimart/utils/archive.rb
minimart-1.1.6 lib/minimart/utils/archive.rb
minimart-1.1.3 lib/minimart/utils/archive.rb
minimart-1.0.2 lib/minimart/utils/archive.rb
minimart-1.0.1 lib/minimart/utils/archive.rb
minimart-0.0.1 lib/minimart/utils/archive.rb