1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
# frozen_string_literal: true
require_relative '../../puppet/module_tool'
require_relative '../../puppet/module_tool/errors'
module Puppet
module ModuleTool
# Control the install location for modules.
class InstallDirectory
include Puppet::ModuleTool::Errors
attr_reader :target
def initialize(target)
@target = target
end
# prepare the module install location. This will create the location if
# needed.
def prepare(module_name, version)
return if @target.directory?
begin
@target.mkpath
Puppet.notice _("Created target directory %{dir}") % { dir: @target }
rescue SystemCallError => orig_error
raise converted_to_friendly_error(module_name, version, orig_error)
end
end
private
ERROR_MAPPINGS = {
Errno::EACCES => PermissionDeniedCreateInstallDirectoryError,
Errno::EEXIST => InstallPathExistsNotDirectoryError,
}
def converted_to_friendly_error(module_name, version, orig_error)
return orig_error unless ERROR_MAPPINGS.include?(orig_error.class)
ERROR_MAPPINGS[orig_error.class].new(orig_error,
:requested_module => module_name,
:requested_version => version,
:directory => @target.to_s)
end
end
end
end
|