HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/module_tool/local_tarball.rb
require 'pathname'
require 'tmpdir'

require 'puppet/forge'
require 'puppet/module_tool'

module Puppet::ModuleTool
  class LocalTarball < SemanticPuppet::Dependency::Source
    attr_accessor :release

    def initialize(filename, strict_semver = true)
      unpack(filename, tmpdir)
      Puppet.debug "Unpacked local tarball to #{tmpdir}"

      mod = Puppet::Module.new('tarball', tmpdir, nil, strict_semver)
      @release = ModuleRelease.new(self, mod)
    end

    def fetch(name)
      if @release.name == name
        [ @release ]
      else
        [ ]
      end
    end

    def prepare(release)
      release.mod.path
    end

    def install(release, dir)
      staging_dir = release.prepare

      module_dir = dir + release.name[/-(.*)/, 1]
      module_dir.rmtree if module_dir.exist?

      # Make sure unpacked module has the same ownership as the folder we are moving it into.
      Puppet::ModuleTool::Applications::Unpacker.harmonize_ownership(dir, staging_dir)

      FileUtils.mv(staging_dir, module_dir)
    end

    class ModuleRelease < SemanticPuppet::Dependency::ModuleRelease
      attr_reader :mod, :install_dir, :metadata

      def initialize(source, mod)
        @mod = mod
        @metadata = mod.metadata
        name = mod.forge_name.tr('/', '-')
        version = SemanticPuppet::Version.parse(mod.version)
        release = "#{name}@#{version}"

        if mod.dependencies
          dependencies = mod.dependencies.map do |dep|
            Puppet::ModuleTool.parse_module_dependency(release, dep, mod.strict_semver?)[0..1]
          end
          dependencies = Hash[dependencies]
        end

        super(source, name, version, dependencies || {})
      end

      def install(dir)
        @source.install(self, dir)
        @install_dir = dir
      end

      def prepare
        @source.prepare(self)
      end
    end

    private

    # Obtain a suitable temporary path for unpacking tarballs
    #
    # @return [String] path to temporary unpacking location
    def tmpdir
      @dir ||= Dir.mktmpdir('local-tarball', Puppet::Forge::Cache.base_path)
    end

    def unpack(file, destination)
      begin
        Puppet::ModuleTool::Applications::Unpacker.unpack(file, destination)
      rescue Puppet::ExecutionFailure => e
        raise RuntimeError, _("Could not extract contents of module archive: %{message}") % { message: e.message }
      end
    end
  end
end