providers/virtualbox: fix package [GH-2739]
This commit is contained in:
parent
f9e418a92b
commit
3f2d3886b2
|
@ -40,6 +40,8 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def recover(env)
|
def recover(env)
|
||||||
|
@env = env
|
||||||
|
|
||||||
# There are certain exceptions that we don't delete the file for.
|
# There are certain exceptions that we don't delete the file for.
|
||||||
ignore_exc = [Errors::PackageOutputDirectory, Errors::PackageOutputExists]
|
ignore_exc = [Errors::PackageOutputDirectory, Errors::PackageOutputExists]
|
||||||
ignore_exc.each do |exc|
|
ignore_exc.each do |exc|
|
||||||
|
|
|
@ -4,8 +4,6 @@ module VagrantPlugins
|
||||||
module ProviderVirtualBox
|
module ProviderVirtualBox
|
||||||
module Action
|
module Action
|
||||||
class Export
|
class Export
|
||||||
attr_reader :temp_dir
|
|
||||||
|
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
@ -16,24 +14,9 @@ module VagrantPlugins
|
||||||
raise Vagrant::Errors::VMPowerOffToPackage if \
|
raise Vagrant::Errors::VMPowerOffToPackage if \
|
||||||
@env[:machine].provider.state.id != :poweroff
|
@env[:machine].provider.state.id != :poweroff
|
||||||
|
|
||||||
setup_temp_dir
|
|
||||||
export
|
export
|
||||||
|
|
||||||
@app.call(env)
|
@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
|
end
|
||||||
|
|
||||||
def export
|
def export
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
require 'vagrant/action/general/package'
|
require 'vagrant/action/general/package'
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
|
@ -8,11 +10,33 @@ module VagrantPlugins
|
||||||
# called in the unit tests.
|
# called in the unit tests.
|
||||||
alias_method :general_call, :call
|
alias_method :general_call, :call
|
||||||
def call(env)
|
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
|
# Just match up a couple environmental variables so that
|
||||||
# the superclass will do the right thing. Then, call the
|
# the superclass will do the right thing. Then, call the
|
||||||
# superclass
|
# superclass
|
||||||
env["package.directory"] = env["export.temp_dir"]
|
env["package.directory"] = env["export.temp_dir"]
|
||||||
|
|
||||||
general_call(env)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue