Class: Vagrant::Action::Box::Unpackage

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/box/unpackage.rb

Overview

Unpackages a downloaded box to a given directory with a given name.

Required Variables

  • download.temp_path - A location for the downloaded box. This is set by the Download action.
  • box - A Box object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Unpackage

Returns a new instance of Unpackage.



19
20
21
22
# File 'lib/vagrant/action/box/unpackage.rb', line 19

def initialize(app, env)
  @app = app
  @env = env
end

Instance Attribute Details

#box_directoryObject (readonly)

Returns the value of attribute box_directory.



17
18
19
# File 'lib/vagrant/action/box/unpackage.rb', line 17

def box_directory
  @box_directory
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/vagrant/action/box/unpackage.rb', line 24

def call(env)
  @env = env

  setup_box_directory
  decompress

  @app.call(@env)
end

#decompressObject



46
47
48
49
50
51
# File 'lib/vagrant/action/box/unpackage.rb', line 46

def decompress
  Dir.chdir(@env["box"].directory) do
    @env.ui.info I18n.t("vagrant.actions.box.unpackage.extracting")
    Archive::Tar::Minitar.unpack(@env["download.temp_path"], @env["box"].directory.to_s)
  end
end

#recover(env) ⇒ Object



33
34
35
36
37
# File 'lib/vagrant/action/box/unpackage.rb', line 33

def recover(env)
  if box_directory && File.directory?(box_directory)
    FileUtils.rm_rf(box_directory)
  end
end

#setup_box_directoryObject



39
40
41
42
43
44
# File 'lib/vagrant/action/box/unpackage.rb', line 39

def setup_box_directory
  raise Errors::BoxAlreadyExists, :name => @env["box"].name if File.directory?(@env["box"].directory)

  FileUtils.mkdir_p(@env["box"].directory)
  @box_directory = @env["box"].directory
end