Sha256: 627b2e829cf8813347f1c5e2aec2d6b46d921802401a6e7f373b1cd51780882e

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

module Vagrant
  module Actions
    module VM
      class Package < Base
        attr_accessor :out_path
        attr_accessor :include_files
        attr_reader :export_action

        def initialize(vm, out_path = nil, include_files = nil, *args)
          super
          @out_path = out_path || "package"
          @include_files = include_files || []
          @temp_path = nil
        end

        def prepare
          # Verify the existance of all the additional files, if any
          @include_files.each do |file|
            raise ActionException.new("#{file} does not exist") unless File.exists?(file)
          end

          # Get the export action and store a reference to it
          @export_action = @runner.find_action(Export)
          raise ActionException.new("Package must be used in conjunction with export.") unless @export_action
        end

        def execute!
          compress
        end

        def tar_path
          File.join(FileUtils.pwd, "#{out_path}#{Vagrant.config.package.extension}")
        end

        def temp_path
          export_action.temp_dir
        end

        def compress
          logger.info "Packaging VM into #{tar_path} ..."
          File.open(tar_path, File::CREAT | File::WRONLY, 0644) do |tar|
            Archive::Tar::Minitar::Output.open(tar) do |output|
              begin
                current_dir = FileUtils.pwd

                include_files.each do |f|
                  logger.info "Packaging additional file: #{f}"
                  Archive::Tar::Minitar.pack_file(f, output)
                end

                FileUtils.cd(temp_path)

                Dir.glob(File.join(".", "*")).each do |entry|
                  Archive::Tar::Minitar.pack_file(entry, output)
                end
              ensure
                FileUtils.cd(current_dir)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
vagrantup-0.2.0 lib/vagrant/actions/vm/package.rb
vagrantup-0.1.4 lib/vagrant/actions/vm/package.rb
vagrant-0.2.0 lib/vagrant/actions/vm/package.rb
vagrant-0.2.0.pre lib/vagrant/actions/vm/package.rb
vagrant-0.1.4 lib/vagrant/actions/vm/package.rb
vagrant-0.1.4.pre.a lib/vagrant/actions/vm/package.rb