diff options
author | Luke Kanies <luke@madstop.com> | 2005-05-11 19:43:01 +0000 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2005-05-11 19:43:01 +0000 |
commit | 4e03ed1822014cc7d062183f92b76e4d6debeb88 (patch) | |
tree | d6353f1bbdd2c5c9002849443c516935748321c6 /lib | |
parent | ec88acf10421b4c2dba38f154d5adcf9ea9202d2 (diff) | |
download | puppet-4e03ed1822014cc7d062183f92b76e4d6debeb88.tar.gz puppet-4e03ed1822014cc7d062183f92b76e4d6debeb88.tar.xz puppet-4e03ed1822014cc7d062183f92b76e4d6debeb88.zip |
i can now execute simple scripts manually!
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@241 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/blink/type/file.rb | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/lib/blink/type/file.rb b/lib/blink/type/file.rb index 20587a6b1..88dac5176 100644 --- a/lib/blink/type/file.rb +++ b/lib/blink/type/file.rb @@ -26,7 +26,7 @@ module Blink def sync begin - File.open(self.path,"w") { # just create an empty file + File.open(self.parent[:path],"w") { # just create an empty file } rescue => detail raise detail @@ -43,9 +43,7 @@ module Blink def retrieve stat = nil - begin - stat = File.stat(self.parent[:path]) - rescue + unless stat = self.parent.stat self.is = -1 Blink.debug "chown state is %d" % self.is return @@ -69,18 +67,22 @@ module Blink end def sync - begin - stat = File.stat(self.parent[:path]) - rescue => error + if @is == -1 + self.parent.stat(true) + self.retrieve + Blink.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + end + + unless self.parent.stat Blink.error "File '%s' does not exist; cannot chown" % self.parent[:path] - return end begin File.chown(self.should,-1,self.parent[:path]) - rescue - raise "failed to sync #{self.parent[:path]}: #{$!}" + rescue => detail + raise "failed to chown '%s' to '%s': %s" % + [self.parent[:path],self.should,detail] end #self.parent.newevent(:event => :inode_changed) @@ -108,22 +110,24 @@ module Blink def retrieve stat = nil - begin - stat = File.stat(self.parent[:path]) - self.is = stat.mode & 007777 - rescue => error + unless stat = self.parent.stat # a value we know we'll never get in reality self.is = -1 return end + self.is = stat.mode & 007777 Blink.debug "chmod state is %o" % self.is end def sync - begin - stat = File.stat(self.parent[:path]) - rescue => error + if @is == -1 + self.parent.stat(true) + self.retrieve + Blink.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + end + + unless self.parent.stat Blink.error "File '%s' does not exist; cannot chmod" % self.parent[:path] return @@ -153,6 +157,11 @@ module Blink # this just doesn't seem right... def sync + unless defined? @is or @is == -1 + self.parent.stat(true) + self.retrieve + Blink.notice "%s: should is '%s'" % [self.class.name,self.should] + end tmp = 0 if self.is == true tmp = 1 @@ -169,9 +178,7 @@ module Blink def retrieve stat = nil - begin - stat = File.stat(self.parent[:path]) - rescue + unless stat = self.parent.stat self.is = -1 Blink.debug "chgrp state is %d" % self.is return @@ -202,10 +209,14 @@ module Blink end def sync - Blink.debug "setting chgrp state to %d" % self.should - begin - stat = File.stat(self.parent[:path]) - rescue => error + Blink.debug "setting chgrp state to %s" % self.should + if @is == -1 + self.parent.stat(true) + self.retrieve + Blink.notice "%s: after refresh, is '%s'" % [self.class.name,@is] + end + + unless self.parent.stat Blink.error "File '%s' does not exist; cannot chgrp" % self.parent[:path] return @@ -224,7 +235,7 @@ module Blink end class Type class File < Type - attr_reader :stat, :path, :params + attr_reader :params # class instance variable @states = [ Blink::State::FileCreate, @@ -241,6 +252,25 @@ module Blink @name = :file @namevar = :path + def initialize(hash) + super + @stat = nil + end + + def stat(refresh = false) + if @stat.nil? or refresh == true + begin + @stat = ::File.stat(self[:path]) + rescue => error + Blink.debug "Failed to stat %s: %s" % + [self[:path],error] + @stat = nil + end + end + + return @stat + end + def sync if self.create and ! FileTest.exist?(self.path) begin |