Sha256: b35e8623ae634c04118b06f2812fec4119cccd76cfc54dda924a6170c5636045

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

module Vagrant
  module Actions
    module Box
      # This action unpackages a downloaded box file into its final
      # box destination within the vagrant home folder.
      class Unpackage < Base

        def execute!
          @runner.invoke_around_callback(:unpackage) do
            setup_box_dir
            decompress
          end
        end

        def rescue(exception)
          if File.directory?(box_dir)
            logger.info "An error occurred, rolling back box unpackaging..."
            FileUtils.rm_rf(box_dir)
          end
        end

        def setup_box_dir
          if File.directory?(box_dir)
            error_and_exit(:box_already_exists, :box_name => @runner.name)
          end

          FileUtils.mkdir_p(box_dir)
        end

        def box_dir
          @runner.directory
        end

        def decompress
          Dir.chdir(box_dir) do
            logger.info "Extracting box to #{box_dir}..."
            Archive::Tar::Minitar.unpack(@runner.temp_path, box_dir)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
vagrantup-0.3.0 lib/vagrant/actions/box/unpackage.rb
vagrant-0.3.0 lib/vagrant/actions/box/unpackage.rb
bmabey-vagrant-0.2.0 lib/vagrant/actions/box/unpackage.rb