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: //proc/thread-self/root/opt/puppetlabs/puppet/lib/ruby/vendor_ruby/puppet/util/storage.rb
require 'yaml'
require 'sync'
require 'singleton'
require 'puppet/util/yaml'

# a class for storing state
class Puppet::Util::Storage
  include Singleton
  include Puppet::Util

  def self.state
    @@state
  end

  def initialize
    self.class.load
  end

  # Return a hash that will be stored to disk.  It's worth noting
  # here that we use the object's full path, not just the name/type
  # combination.  At the least, this is useful for those non-isomorphic
  # types like exec, but it also means that if an object changes locations
  # in the configuration it will lose its cache.
  def self.cache(object)
    if object.is_a?(Symbol)
      name = object
    else
      name = object.to_s
    end

    @@state[name] ||= {}
  end

  def self.clear
    @@state.clear
  end

  def self.init
    @@state = {}
  end

  self.init

  def self.load
    Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir])
    filename = Puppet[:statefile]

    unless Puppet::FileSystem.exist?(filename)
      self.init if @@state.nil?
      return
    end
    unless File.file?(filename)
      Puppet.warning(_("Checksumfile %{filename} is not a file, ignoring") % { filename: filename })
      return
    end
    Puppet::Util.benchmark(:debug, "Loaded state in %{seconds} seconds") do
      begin
        @@state = Puppet::Util::Yaml.load_file(filename)
      rescue Puppet::Util::Yaml::YamlLoadError => detail
        Puppet.err _("Checksumfile %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail }

        begin
          File.rename(filename, filename + ".bad")
        rescue
          raise Puppet::Error, _("Could not rename corrupt %{filename}; remove manually") % { filename: filename }, detail.backtrace
        end
      end
    end

    unless @@state.is_a?(Hash)
      Puppet.err _("State got corrupted")
      self.init
    end
  end

  def self.stateinspect
    @@state.inspect
  end

  def self.store
    Puppet.debug "Storing state"

    Puppet.info _("Creating state file %{file}") % { file: Puppet[:statefile] } unless Puppet::FileSystem.exist?(Puppet[:statefile])

    if Puppet[:statettl] == 0 || Puppet[:statettl] == Float::INFINITY
      Puppet.debug "Not pruning old state cache entries"
    else
      Puppet::Util.benchmark(:debug, "Pruned old state cache entries in %{seconds} seconds") do
        ttl_cutoff = Time.now - Puppet[:statettl]

        @@state.reject! do |k,v|
          @@state[k][:checked] && @@state[k][:checked] < ttl_cutoff
        end
      end
    end

    Puppet::Util.benchmark(:debug, "Stored state in %{seconds} seconds") do
      Puppet::Util::Yaml.dump(@@state, Puppet[:statefile])
    end
  end
end