def cache_version_unpacked!(version)
path = version_unpacked_cache_path(version)
return if path.directory?
check_puppet_module_options
path.mkpath
target = vendored?(name, version) ? vendored_path(name, version).to_s : name
module_repository = source.to_s
if Forge.client_api_version() > 1 and module_repository =~ %r{^http(s)?://forge\.puppetlabs\.com}
module_repository = "https://forgeapi.puppetlabs.com"
warn { "Replacing Puppet Forge API URL to use v3 #{module_repository} as required by your client version #{Librarian::Puppet.puppet_version}" }
end
m = module_repository.match(%r{^http(s)?://forge(api)?\.puppetlabs\.com})
if Forge.client_api_version() == 1 and m
ssl = m[1]
if ssl and Librarian::Puppet::puppet_gem_version < Gem::Version.create('3.0.0')
warn { "Using plain http as your version of Puppet #{Librarian::Puppet::puppet_gem_version} can't download from forge.puppetlabs.com using https" }
ssl = nil
end
module_repository = "http#{ssl}://forge.puppetlabs.com"
end
command = ??{puppet module install --version
command.push(*[path.to_s, "--module_repository", module_repository, "--modulepath", path.to_s, "--module_working_dir", path.to_s, "--ignore-dependencies", target])
debug { "Executing puppet module install for #{name} #{version}: #{command.join(" ")}" }
begin
Librarian::Posix.run!(command)
rescue Posix::CommandFailure => e
begin
path.unlink
rescue => u
debug("Unable to rollback path #{path}: #{u}")
end
tar = Dir[File.join(path.to_s, "**/*.tar.gz")]
msg = ""
if e.message =~ /Unexpected EOF in archive/ and !tar.empty?
file = tar.first
msg = " (looks like an incomplete download of #{file})"
end
raise Error, "Error executing puppet module install#{msg}. Check that this command succeeds:\n#{command.join(" ")}\nError:\n#{e.message}"
end
end
def check_puppet_module_options
min_version = Gem::Version.create('2.7.13')
if Librarian::Puppet.puppet_gem_version < min_version
raise Error, "To get modules from the forge, we use the puppet faces module command. For this you need at least puppet version 2.7.13 and you have #{puppet_version}"
end
end
def vendor_cache(name, version)
url = url(name, version)
path = vendored_path(name, version).to_s
debug { "Downloading #{url} into #{path}"}
environment.vendor!
File.open(path, 'wb') do |f|
open(url, "rb") do |input|
f.write(input.read)
end
end
end
end