Sha256: 69b72e80f484cba4e9d91736e13bdb4f76b1375753351c7589b269cc998eee89

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

require 'pathname'
require 'tmpdir'

module Puppet::ModuleTool
  module Applications
    class Unpacker < Application

      def initialize(filename, options = {})
        @filename = Pathname.new(filename)
        parsed = parse_filename(filename)
        super(options)
        @module_dir = Pathname.new(options[:target_dir]) + parsed[:dir_name]
      end

      def run
        extract_module_to_install_dir

        # Return the Pathname object representing the directory where the
        # module release archive was unpacked the to, and the module release
        # name.
        @module_dir
      end

      private
      def extract_module_to_install_dir
        delete_existing_installation_or_abort!

        build_dir = Puppet::Forge::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename.to_s)}"
        build_dir.mkpath
        begin
          unless system "tar xzf #{@filename} -C #{build_dir}"
            raise RuntimeError, "Could not extract contents of module archive."
          end
          # grab the first directory
          extracted = build_dir.children.detect { |c| c.directory? }
          FileUtils.mv extracted, @module_dir
        ensure
          build_dir.rmtree
        end
      end

      def delete_existing_installation_or_abort!
        return unless @module_dir.exist?
        FileUtils.rm_rf(@module_dir, :secure => true)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
librarian-puppet-0.9.4 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/module_tool/applications/unpacker.rb
librarian-puppet-0.9.3 vendor/gems/ruby/1.8/gems/puppet-2.7.18/lib/puppet/module_tool/applications/unpacker.rb
puppet-2.7.18 lib/puppet/module_tool/applications/unpacker.rb
puppet-2.7.17 lib/puppet/module_tool/applications/unpacker.rb
puppet-2.7.16 lib/puppet/module_tool/applications/unpacker.rb
puppet-2.7.14 lib/puppet/module_tool/applications/unpacker.rb