Method: Puppet::Transaction::Persistence#load

Defined in:
lib/puppet/transaction/persistence.rb

#loadObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Load data from the persistence store on disk.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/transaction/persistence.rb', line 44

def load
  filename = Puppet[:transactionstorefile]
  unless Puppet::FileSystem.exist?(filename)
    return
  end
  unless File.file?(filename)
    Puppet.warning(_("Transaction store file %{filename} is not a file, ignoring") % { filename: filename })
    return
  end

  result = nil
  Puppet::Util.benchmark(:debug, _("Loaded transaction store file")) do
    begin
      result = Puppet::Util::Yaml.load_file(filename, false, true)
    rescue Puppet::Util::Yaml::YamlLoadError => detail
      Puppet.log_exception(detail, _("Transaction store file %{filename} is corrupt (%{detail}); replacing") % { filename: filename, detail: detail }, { :level => :warning })

      begin
        File.rename(filename, filename + ".bad")
      rescue => detail
        Puppet.log_exception(detail, _("Unable to rename corrupt transaction store file: %{detail}") % { detail: detail })
        raise Puppet::Error, _("Could not rename corrupt transaction store file %{filename}; remove manually") % { filename: filename }, detail.backtrace
      end

      result = {}
    end
  end

  unless result.is_a?(Hash)
    Puppet.err _("Transaction store file %{filename} is valid YAML but not returning a hash. Check the file for corruption, or remove it before continuing.") % { filename: filename }
    return
  end

  @old_data = result
end