providers/virtualbox: fix package [GH-2739]
This commit is contained in:
parent
f9e418a92b
commit
3f2d3886b2
|
@ -40,6 +40,8 @@ module Vagrant
|
|||
end
|
||||
|
||||
def recover(env)
|
||||
@env = env
|
||||
|
||||
# There are certain exceptions that we don't delete the file for.
|
||||
ignore_exc = [Errors::PackageOutputDirectory, Errors::PackageOutputExists]
|
||||
ignore_exc.each do |exc|
|
||||
|
|
|
@ -4,8 +4,6 @@ module VagrantPlugins
|
|||
module ProviderVirtualBox
|
||||
module Action
|
||||
class Export
|
||||
attr_reader :temp_dir
|
||||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
@ -16,24 +14,9 @@ module VagrantPlugins
|
|||
raise Vagrant::Errors::VMPowerOffToPackage if \
|
||||
@env[:machine].provider.state.id != :poweroff
|
||||
|
||||
setup_temp_dir
|
||||
export
|
||||
|
||||
@app.call(env)
|
||||
|
||||
recover(env) # called to cleanup temp directory
|
||||
end
|
||||
|
||||
def recover(env)
|
||||
if temp_dir && File.exist?(temp_dir)
|
||||
FileUtils.rm_rf(temp_dir)
|
||||
end
|
||||
end
|
||||
|
||||
def setup_temp_dir
|
||||
@env[:ui].info I18n.t("vagrant.actions.vm.export.create_dir")
|
||||
@temp_dir = @env["export.temp_dir"] = @env[:tmp_path].join(Time.now.to_i.to_s)
|
||||
FileUtils.mkpath(@env["export.temp_dir"])
|
||||
end
|
||||
|
||||
def export
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'fileutils'
|
||||
|
||||
require 'vagrant/action/general/package'
|
||||
|
||||
module VagrantPlugins
|
||||
|
@ -8,11 +10,33 @@ module VagrantPlugins
|
|||
# called in the unit tests.
|
||||
alias_method :general_call, :call
|
||||
def call(env)
|
||||
# Setup the temporary directory
|
||||
@temp_dir = env[:tmp_path].join(Time.now.to_i.to_s)
|
||||
env["export.temp_dir"] = @temp_dir
|
||||
FileUtils.mkpath(env["export.temp_dir"])
|
||||
|
||||
# Just match up a couple environmental variables so that
|
||||
# the superclass will do the right thing. Then, call the
|
||||
# superclass
|
||||
env["package.directory"] = env["export.temp_dir"]
|
||||
|
||||
general_call(env)
|
||||
|
||||
# Always call recover to clean up the temp dir
|
||||
clean_temp_dir
|
||||
end
|
||||
|
||||
def recover(env)
|
||||
clean_temp_dir
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def clean_temp_dir
|
||||
if @temp_dir && File.exist?(@temp_dir)
|
||||
FileUtils.rm_rf(@temp_dir)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue