summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-07-11 18:45:31 +0000
committerLuke Kanies <luke@madstop.com>2005-07-11 18:45:31 +0000
commitd14dc32d1800e61a4b509ab8410c848ae472bdd1 (patch)
tree0acde8366233d2779d68abde39f4ba8747ca8b52 /lib
parent96f3980a57f8fd24aff801420a0813bad9bb20d7 (diff)
downloadpuppet-d14dc32d1800e61a4b509ab8410c848ae472bdd1.tar.gz
puppet-d14dc32d1800e61a4b509ab8410c848ae472bdd1.tar.xz
puppet-d14dc32d1800e61a4b509ab8410c848ae472bdd1.zip
fixing storage class; it was not actually correctly retrieving state from disk
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@355 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/storage.rb40
1 files changed, 30 insertions, 10 deletions
diff --git a/lib/puppet/storage.rb b/lib/puppet/storage.rb
index 28d593db0..5dac7dc35 100644
--- a/lib/puppet/storage.rb
+++ b/lib/puppet/storage.rb
@@ -4,26 +4,44 @@ module Puppet
# a class for storing state
class Storage
include Singleton
- @@state = Hash.new { |hash,key|
- hash[key] = Hash.new(nil)
- }
- @@splitchar = "\t"
def initialize
self.class.load
end
+ def Storage.clear
+ @@state = nil
+ Storage.init
+ end
+
+ def Storage.init
+ @@state = Hash.new { |hash,key|
+ hash[key] = Hash.new(nil)
+ }
+ @@splitchar = "\t"
+ end
+
+ self.init
+
def Storage.load
- # XXX I should probably use a better default state dir
- Puppet[:statefile] ||= "/var/tmp/puppetstate"
- return unless File.exists?(Puppet[:statefile])
+ if Puppet[:statefile].nil?
+ raise "Somehow the statefile is nil"
+ end
+
+ unless File.exists?(Puppet[:statefile])
+ Puppet.info "Statefile %s does not exist" % Puppet[:statefile]
+ return
+ end
+ Puppet.debug "Loading statefile %s" % Puppet[:statefile]
File.open(Puppet[:statefile]) { |file|
- file.gets { |line|
+ file.each { |line|
myclass, key, value = line.split(@@splitchar)
- @@state[myclass][key] = Marshal::load(value)
+ @@state[eval(myclass)][key] = Marshal::load(value)
}
}
+
+ Puppet.debug "Loaded state is %s" % @@state.inspect
end
def Storage.state(myclass)
@@ -39,7 +57,7 @@ module Puppet
begin
Puppet.recmkdir(Puppet[:statefile])
Puppet.info "Creating state directory %s" %
- File.basename(Puppet[:statefile])
+ File.dirname(Puppet[:statefile])
rescue => detail
Puppet.err "Could not create state file: %s" % detail
return
@@ -58,6 +76,8 @@ module Puppet
}
}
}
+
+ Puppet.debug "Stored state is %s" % @@state.inspect
end
end
end