lib/vagrant/action/builtin/handle_box_url.rb in tnargav-1.2.3 vs lib/vagrant/action/builtin/handle_box_url.rb in tnargav-1.3.3

- old
+ new

@@ -1,7 +1,9 @@ require "thread" +require "log4r" + module Vagrant module Action module Builtin # This built-in middleware handles the `box_url` setting, downloading # the box if necessary. You should place this early in your middleware @@ -11,13 +13,20 @@ @@big_lock = Mutex.new @@handle_box_url_locks = Hash.new { |h,k| h[k] = Mutex.new } def initialize(app, env) @app = app + @logger = Log4r::Logger.new("vagrant::action::builtin::handle_box_url") end def call(env) + if !env[:machine].config.vm.box || !env[:machine].config.vm.box_url + @logger.info("Skipping HandleBoxUrl because box or box_url not set.") + @app.call(env) + return + end + if !env[:machine].box # Get a "big lock" to make sure that our more fine grained # lock access is thread safe. lock = nil @@big_lock.synchronize do @@ -27,22 +36,21 @@ # We can assume a box URL is set because the Vagrantfile # validation should do this for us. If not, though, we do # raise a terrible runtime error. box_name = env[:machine].config.vm.box box_url = env[:machine].config.vm.box_url + box_download_insecure = env[:machine].config.vm.box_download_insecure lock.synchronize do # First see if we actually have the box now. has_box = false - formats = env[:machine].provider_options[:box_format] || + box_formats = env[:machine].provider_options[:box_format] || env[:machine].provider_name - [formats].flatten.each do |format| - if env[:box_collection].find(box_name, format) - has_box = true - break - end + if env[:box_collection].find(box_name, box_formats) + has_box = true + break end if !has_box # Add the box then reload the box collection so that it becomes # aware of it. @@ -51,11 +59,12 @@ :name => box_name, :provider => env[:machine].provider_name) begin env[:action_runner].run(Vagrant::Action.action_box_add, { + :box_download_insecure => box_download_insecure, :box_name => box_name, - :box_provider => env[:machine].provider_name, + :box_provider => box_formats, :box_url => box_url }) rescue Errors::BoxAlreadyExists # Just ignore this, since it means the next part will succeed! # This can happen in a multi-threaded environment.