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.
This commit is contained in:
parent
7b89374dce
commit
a33892e4df
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue