Sha256: fbc517938ea9b80b4b0d2500cf4cccb89a026553e0d2ac067be4b2d953368866

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

# 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 if not 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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
puppet-8.5.1 lib/puppet/module_tool/install_directory.rb
puppet-8.5.1-x86-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.5.1-x64-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.5.1-universal-darwin lib/puppet/module_tool/install_directory.rb
puppet-8.5.0 lib/puppet/module_tool/install_directory.rb
puppet-8.5.0-x86-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.5.0-x64-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.5.0-universal-darwin lib/puppet/module_tool/install_directory.rb
puppet-8.4.0 lib/puppet/module_tool/install_directory.rb
puppet-8.4.0-x86-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.4.0-x64-mingw32 lib/puppet/module_tool/install_directory.rb
puppet-8.4.0-universal-darwin lib/puppet/module_tool/install_directory.rb