From 7b89374dcebe1a534f95a70885e56ac81399da23 Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Tue, 1 Nov 2016 14:57:06 +0000 Subject: [PATCH 1/2] Fix version sorting in box_collection.rb --- lib/vagrant/box_collection.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index 5a295df29..d3cca1b83 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -276,7 +276,7 @@ module Vagrant next if !versiondir.directory? next if versiondir.basename.to_s.start_with?(".") - version = versiondir.basename.to_s + version = Gem::Version.new(versiondir.basename.to_s) end.compact # Traverse through versions with the latest version first @@ -286,7 +286,7 @@ module Vagrant next end - versiondir = box_directory.join(v) + versiondir = box_directory.join(v.to_s) providers.each do |provider| provider_dir = versiondir.join(provider.to_s) next if !provider_dir.directory? From a33892e4df0fc8aef9081ebc753cada6a774f9eb Mon Sep 17 00:00:00 2001 From: David O'Rourke Date: Tue, 1 Nov 2016 15:59:23 +0000 Subject: [PATCH 2/2] Maintain a version dir map in box_collection. This is required since Gem::Version will mangle pre-release version numbers. To get around this, we keep a mapping of `Gem::Version.to_s => versiondir.` This allows us to properly sort by version when picking a box while still returning pristine versiondirs when required. --- lib/vagrant/box_collection.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/vagrant/box_collection.rb b/lib/vagrant/box_collection.rb index d3cca1b83..17b0eb405 100644 --- a/lib/vagrant/box_collection.rb +++ b/lib/vagrant/box_collection.rb @@ -272,21 +272,30 @@ module Vagrant return nil end + # Keep a mapping of Gem::Version mangled versions => directories. + # ie. 0.1.0.pre.alpha.2 => 0.1.0-alpha.2 + # This is so we can sort version numbers properly here, but still + # refer to the real directory names in path checks below and pass an + # unmangled version string to Box.new + version_dir_map = {} + versions = box_directory.children(true).map do |versiondir| next if !versiondir.directory? next if versiondir.basename.to_s.start_with?(".") version = Gem::Version.new(versiondir.basename.to_s) + version_dir_map[version.to_s] = versiondir.basename.to_s + version end.compact # Traverse through versions with the latest version first versions.sort.reverse.each do |v| - if !requirements.all? { |r| r.satisfied_by?(Gem::Version.new(v)) } + if !requirements.all? { |r| r.satisfied_by?(v) } # Unsatisfied version requirements next end - versiondir = box_directory.join(v.to_s) + versiondir = box_directory.join(version_dir_map[v.to_s]) providers.each do |provider| provider_dir = versiondir.join(provider.to_s) next if !provider_dir.directory? @@ -303,7 +312,7 @@ module Vagrant end return Box.new( - name, provider, v, provider_dir, + name, provider, version_dir_map[v.to_s], provider_dir, metadata_url: metadata_url, ) end