lib/puppet/storage.rb in puppet-0.13.0 vs lib/puppet/storage.rb in puppet-0.13.1

- old
+ new

@@ -1,12 +1,14 @@ require 'yaml' +require 'sync' +#require 'puppet/lockfile' module Puppet # a class for storing state class Storage include Singleton - + def initialize self.class.load end # Return a hash that will be stored to disk. It's worth noting @@ -44,13 +46,11 @@ unless defined? @@state and ! @@state.nil? self.init end return end - #Puppet.debug "Loading statefile %s" % Puppet[:statefile] - Puppet::Util.lock(Puppet[:statefile]) { |file| - #@@state = Marshal.load(file) + 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] @@ -61,11 +61,11 @@ raise Puppet::Error, "Could not rename corrupt %s; remove manually" % Puppet[:statefile] end end - } + end unless @@state.is_a?(Hash) Puppet.err "State got corrupted" self.init end @@ -76,11 +76,11 @@ def self.stateinspect @@state.inspect end def self.store - Puppet.debug "Storing state" + #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]) @@ -92,15 +92,13 @@ unless FileTest.exist?(Puppet[:statefile]) Puppet.info "Creating state file %s" % Puppet[:statefile] end - Puppet::Util.lock( - Puppet[:statefile], "w", 0600 - ) { |file| + Puppet::Util.writelock(Puppet[:statefile], 0600) do |file| file.print YAML.dump(@@state) - } + end end end end -# $Id: storage.rb 848 2006-01-24 06:01:58Z luke $ +# $Id: storage.rb 897 2006-02-12 18:08:39Z luke $