lib/puppet/storage.rb in puppet-0.13.6 vs lib/puppet/storage.rb in puppet-0.16.0
- old
+ new
@@ -4,10 +4,11 @@
module Puppet
# a class for storing state
class Storage
include Singleton
+ include Puppet::Util
def initialize
self.class.load
end
@@ -45,23 +46,25 @@
unless defined? @@state and ! @@state.nil?
self.init
end
return
end
- Puppet::Util.readlock(Puppet[:statefile]) do |file|
- begin
- @@state = YAML.load(file)
- rescue => detail
- Puppet.err "Checksumfile %s is corrupt (%s); replacing" %
- [Puppet[:statefile], detail]
+ Puppet::Util.benchmark(:debug, "Loaded state") do
+ Puppet::Util.readlock(Puppet[:statefile]) do |file|
begin
- File.rename(Puppet[:statefile],
- Puppet[:statefile] + ".bad")
- rescue
- raise Puppet::Error,
- "Could not rename corrupt %s; remove manually" %
- Puppet[:statefile]
+ @@state = YAML.load(file)
+ rescue => detail
+ Puppet.err "Checksumfile %s is corrupt (%s); replacing" %
+ [Puppet[:statefile], detail]
+ begin
+ File.rename(Puppet[:statefile],
+ Puppet[:statefile] + ".bad")
+ rescue
+ raise Puppet::Error,
+ "Could not rename corrupt %s; remove manually" %
+ Puppet[:statefile]
+ end
end
end
end
unless @@state.is_a?(Hash)
@@ -77,29 +80,20 @@
end
def self.store
Puppet.config.use(:puppet)
Puppet.debug "Storing state"
-# unless FileTest.directory?(File.dirname(Puppet[:statefile]))
-# begin
-# Puppet.recmkdir(File.dirname(Puppet[:statefile]))
-# Puppet.info "Creating state directory %s" %
-# File.dirname(Puppet[:statefile])
-# rescue => detail
-# Puppet.err "Could not create state file: %s" % detail
-# return
-# end
-# end
unless FileTest.exist?(Puppet[:statefile])
Puppet.info "Creating state file %s" % Puppet[:statefile]
end
- Puppet::Util.writelock(Puppet[:statefile], 0600) do |file|
- file.print YAML.dump(@@state)
+ Puppet::Util.benchmark(:debug, "Stored state") do
+ Puppet::Util.writelock(Puppet[:statefile], 0660) do |file|
+ file.print YAML.dump(@@state)
+ end
end
- Puppet.debug "Stored state"
end
end
end
-# $Id: storage.rb 965 2006-03-02 07:30:14Z luke $
+# $Id: storage.rb 1098 2006-04-10 22:13:10Z luke $