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



48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant/action/box/unpackage.rb', line 48

def decompress
  Dir.chdir(@env["box_directory"]) do
    @env[:ui].info I18n.t("vagrant.actions.box.unpackage.extracting")
    begin
      Archive::Tar::Minitar.unpack(@env["download.temp_path"], @env["box_directory"].to_s)
    rescue SystemCallError
      raise Errors::BoxUnpackageFailure
    end
  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
45
46
# File 'lib/vagrant/action/box/unpackage.rb', line 39

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

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