diff options
| author | Luke Kanies <luke@madstop.com> | 2005-07-19 06:10:33 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-07-19 06:10:33 +0000 |
| commit | de91dbdc5c554136437250daa512050f6d46fbc8 (patch) | |
| tree | 745391ccfa27e682f272364ef15e7c092ce2f68e /lib | |
| parent | 9ba72f574aba66020913c7ac837634d5ca0fb13e (diff) | |
| download | puppet-de91dbdc5c554136437250daa512050f6d46fbc8.tar.gz puppet-de91dbdc5c554136437250daa512050f6d46fbc8.tar.xz puppet-de91dbdc5c554136437250daa512050f6d46fbc8.zip | |
temp commit before i change the whole way that i am doing source + recursion
git-svn-id: https://reductivelabs.com/svn/puppet/library/trunk@421 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet.rb | 9 | ||||
| -rw-r--r-- | lib/puppet/event.rb | 30 | ||||
| -rw-r--r-- | lib/puppet/transaction.rb | 15 | ||||
| -rw-r--r-- | lib/puppet/type.rb | 17 | ||||
| -rw-r--r-- | lib/puppet/type/pfile.rb | 593 | ||||
| -rw-r--r-- | lib/puppet/type/service.rb | 14 |
6 files changed, 532 insertions, 146 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb index 415bd253b..07198ffa3 100644 --- a/lib/puppet.rb +++ b/lib/puppet.rb @@ -17,6 +17,15 @@ require 'puppet/log' module Puppet class Error < RuntimeError attr_accessor :stack + def initialize(message) + @message = message + + @stack = caller + end + + def to_s + return @message + end end class DevError < Error; end diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb index 91046d9af..74804e6df 100644 --- a/lib/puppet/event.rb +++ b/lib/puppet/event.rb @@ -26,7 +26,7 @@ module Puppet # this is probably wicked-slow self.send(method.to_s + "=",value) } - debug "New Subscription: '%s' => '%s'" % + Puppet.debug "New Subscription: '%s' => '%s'" % [@source,@event] end @@ -39,23 +39,24 @@ module Puppet # the last, a later-refreshed object could somehow be connected # to the "old" object rather than "new" # but we're pretty far from that being a problem + event = nil if transaction.triggercount(self) > 0 - debug "%s has already run" % self + Puppet.debug "%s has already run" % self else - debug "'%s' matched '%s'; triggering '%s' on '%s'" % + Puppet.debug "'%s' matched '%s'; triggering '%s' on '%s'" % [@source,@event,@method,@target] begin if @target.respond_to?(@method) - @target.send(@method) + event = @target.send(@method) else - debug "'%s' of type '%s' does not respond to '%s'" % + Puppet.debug "'%s' of type '%s' does not respond to '%s'" % [@target,@target.class,@method.inspect] end rescue => detail # um, what the heck do i do when an object fails to refresh? # shouldn't that result in the transaction rolling back? # XXX yeah, it should - err "'%s' failed to %s: '%s'" % + Puppet.err "'%s' failed to %s: '%s'" % [@target,@method,detail] raise #raise "We need to roll '%s' transaction back" % @@ -63,6 +64,7 @@ module Puppet end transaction.triggered(self) end + return event end end @@ -73,7 +75,7 @@ module Puppet @@subscriptions = [] def self.process - debug "Processing events" + Puppet.debug "Processing events" @@events.each { |event| @@subscriptions.find_all { |sub| #debug "Sub source: '%s'; event object: '%s'" % @@ -82,7 +84,7 @@ module Puppet (sub.event == event.event or sub.event == :ALL_EVENTS) }.each { |sub| - debug "Found subscription to %s" % event + Puppet.debug "Found subscription to %s" % event sub.trigger(event.transaction) } } @@ -136,7 +138,7 @@ class Puppet::NotUsed # access to the actual hash, which is silly def action if not defined? @actions - debug "defining action hash" + Puppet.debug "defining action hash" @actions = Hash.new end @actions @@ -150,9 +152,9 @@ class Puppet::NotUsed # event handling should probably be taking place in a central process, # but.... def event(event,obj) - debug "#{self} got event #{event} from #{obj}" + Puppet.debug "#{self} got event #{event} from #{obj}" if @actions.key?(event) - debug "calling it" + Puppet.debug "calling it" @actions[event].call(self,obj,event) else p @actions @@ -176,7 +178,7 @@ class Puppet::NotUsed @notify[event] = Array.new end unless @notify[event].include?(obj) - debug "pushing event '%s' for object '%s'" % [event,obj] + Puppet.debug "pushing event '%s' for object '%s'" % [event,obj] @notify[event].push(obj) end # } @@ -195,9 +197,9 @@ class Puppet::NotUsed if (@notify.include?(event) and (! @notify[event].empty?) ) @notify[event].each { |obj| subscribers.push(obj) } end - debug "triggering #{event}" + Puppet.debug "triggering #{event}" subscribers.each { |obj| - debug "calling #{event} on #{obj}" + Puppet.debug "calling #{event} on #{obj}" obj.event(event,self) } end diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index 2b7d43f8f..8766460ea 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -37,10 +37,13 @@ class Transaction #--------------------------------------------------------------- #--------------------------------------------------------------- - # i don't need to worry about ordering, because it's not possible to specify - # an object as a dependency unless it's already been mentioned within the language - # thus, an object gets defined, then mentioned as a dependency, and the objects - # are synced in that order automatically + # okay, here's the deal: + # a given transaction maps directly to a component, and each transaction + # will only ever receive changes from its respective component + # so, when looking for subscribers, we need to first see if the object + # that actually changed had any direct subscribers + # then, we need to pass the event to the object's containing component, + # to see if it or any of its parents have subscriptions on the event def evaluate Puppet.debug "executing %s changes or transactions" % @changes.length @@ -49,6 +52,8 @@ class Transaction change.transaction = self events = nil begin + # use an array, so that changes can return more than one + # event if they want events = [change.forward].flatten #@@changed.push change.state.parent rescue => detail @@ -82,7 +87,7 @@ class Transaction event.nil? }.each { |event| # this handles subscriptions on the components, rather than - # on idividual objects + # on individual objects self.component.subscribers?(event).each { |sub| sub.trigger(self) } diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index fd889ddd3..d5dafcd38 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -428,7 +428,7 @@ class Type < Puppet::Element if @states.include?(mname) @states[mname].should = value else - #warning "Creating state %s for %s" % + #Puppet.warning "Creating state %s for %s" % # [stateklass.name,self.name] @states[mname] = stateklass.new( :parent => self, @@ -480,7 +480,8 @@ class Type < Puppet::Element #--------------------------------------------------------------- # iterate across the existing states def eachstate - states.each { |state| + # states() is a private method + states().each { |state| yield state } end @@ -673,6 +674,7 @@ class Type < Puppet::Element # sync the changes to disk, and return the events generated by the changes def sync events = self.collect { |child| + Puppet.warning "Syncing %s" % child child.sync }.reject { |event| ! (event.is_a?(Symbol) or event.is_a?(String)) @@ -706,8 +708,9 @@ class Type < Puppet::Element # rather than 'each' def evaluate unless defined? @evalcount - err "No evalcount defined on '%s' of type '%s'" % + Puppet.err "No evalcount defined on '%s' of type '%s'" % [self.name,self.class] + @evalcount = 0 end # if we're a metaclass and we've already evaluated once... #if self.metaclass and @evalcount > 0 @@ -724,7 +727,9 @@ class Type < Puppet::Element unless self.insync? # add one to the number of out-of-sync instances Puppet::Metric.add(self.class,self,:outofsync,1) - changes << states.find_all { |state| + + # states() is a private method, returning an ordered list + changes << states().find_all { |state| ! state.insync? }.collect { |state| Puppet::StateChange.new(state) @@ -740,6 +745,8 @@ class Type < Puppet::Element # now record how many changes we've resulted in Puppet::Metric.add(self.class,self,:changes,changes.length) + Puppet.warning "%s resulted in %s changes" % + [self.name, changes.length] return changes.flatten end #--------------------------------------------------------------- @@ -904,7 +911,7 @@ end require 'puppet/type/service' require 'puppet/type/exec' require 'puppet/type/pfile' -require 'puppet/type/symlink' +#require 'puppet/type/symlink' require 'puppet/type/package' require 'puppet/type/component' require 'puppet/statechange' diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb index 44d998c1f..99d66e47f 100644 --- a/lib/puppet/type/pfile.rb +++ b/lib/puppet/type/pfile.rb @@ -4,6 +4,7 @@ require 'digest/md5' require 'etc' +require 'fileutils' require 'puppet/type/state' module Puppet @@ -18,33 +19,63 @@ module Puppet def should=(value) # default to just about anything meaning 'true' - if value == false or value.nil? + case value + when "false", false, nil: @should = false + when "true", true, "file", "plain", /^f/: + @should = "file" + when "directory", /^d/: + @should = "directory" else - @should = true + error = Puppet::Error.new "Cannot create files of type %s" % + value + raise error end end def retrieve - stat = nil + if stat = self.parent.stat(true) + @is = stat.ftype + else + @is = -1 + end - self.is = FileTest.exist?(self.parent[:path]) Puppet.debug "'exists' state is %s" % self.is end def sync + if defined? @synced + Puppet.err "We've already been synced?" + end + event = nil begin - File.open(self.parent[:path],"w") { # just create an empty file - } + case @should + when "file": + File.open(self.parent[:path],"w") { # just create an empty file + } + event = :file_created + when "directory": + Dir.mkdir(self.parent.name) + event = :directory_created + else + error = Puppet::Error.new( + "Somehow got told to create a %s file" % @should) + raise error + end rescue => detail - raise detail + error = Puppet::Error.new "Could not create %s: %s" % + [@should, detail] + raise error end - return :file_created + @synced = true + return event end end class PFileChecksum < Puppet::State + attr_accessor :checktype + @name = :checksum @event = :file_modified @@ -71,15 +102,22 @@ module Puppet @checktype = "md5" end + unless FileTest.exists?(self.parent.name) + Puppet.info "File %s does not exist" % self.parent.name + self.is = -1 + return + end + sum = "" case @checktype when "md5": if FileTest.directory?(self.parent[:path]) - info "Cannot MD5 sum directory %s" % + Puppet.info "Cannot MD5 sum directory %s" % self.parent[:path] - # because we cannot sum directories, just remove - # the state entirely + # because we cannot sum directories, just delete ourselves + # from the file + # is/should so we won't sync self.parent.delete(self.name) return else @@ -89,16 +127,23 @@ module Puppet end when "md5lite": if FileTest.directory?(self.parent[:path]) - info "Cannot MD5 sum directory %s" % + Puppet.info "Cannot MD5 sum directory %s" % self.parent[:path] - # because we cannot sum directories, just remove - # the state entirely - self.parent.delete(self.name) + # because we cannot sum directories, just delete ourselves + # from the file + # is/should so we won't sync return else File.open(self.parent[:path]) { |file| - sum = Digest::MD5.hexdigest(file.read(512)) + text = file.read(512) + if text.nil? + Puppet.info "Not checksumming empty file %s" % + self.parent.name + sum = 0 + else + sum = Digest::MD5.hexdigest(text) + end } end when "timestamp","mtime": @@ -113,12 +158,29 @@ module Puppet end - # at this point, we don't actually modify the system, we just kick - # off an event if we detect a change + # at this point, we don't actually modify the system, we modify + # the stored state to reflect the current state, and then kick + # off an event to mark any changes def sync if @is.nil? - Puppet.err "@is is nil" + error = Puppet::Error.new "Checksum state for %s is somehow nil" % + self.parent.name + raise error + end + + if @is == -1 + self.retrieve + Puppet.debug "%s(%s): after refresh, is '%s'" % + [self.class.name,self.parent.name,@is] + + # if we still can't retrieve a checksum, it means that + # the file still doesn't exist + if @is == -1 + Puppet.warning "File %s still does not exist" % self.parent.name + return nil + end end + if self.updatesum # set the @should value to the new @is value # most important for testing @@ -134,27 +196,40 @@ module Puppet def updatesum result = false state = Puppet::Storage.state(self) - unless state.include?(self.parent[:path]) + unless state.include?(self.parent.name) Puppet.debug "Initializing state hash for %s" % - self.parent[:path] + self.parent.name - state[self.parent[:path]] = Hash.new + state[self.parent.name] = Hash.new + end + + if @is == -1 + error = Puppet::Error.new("%s has invalid checksum" % + self.parent.name) + raise error + #elsif @should == -1 + # error = Puppet::Error.new("%s has invalid 'should' checksum" % + # self.parent.name) + # raise error end + # if we're replacing, vs. updating - if state[self.parent[:path]].include?(@checktype) + if state[self.parent.name].include?(@checktype) unless defined? @should - raise "@should is not initialized for %s, even though we found a checksum" % self.parent[:path] + raise Puppet::Error.new( + "@should is not initialized for %s, even though we found a checksum" % self.parent[:path] + ) end Puppet.debug "Replacing checksum %s with %s" % - [state[self.parent[:path]][@checktype],@is] + [state[self.parent.name][@checktype],@is] Puppet.debug "@is: %s; @should: %s" % [@is,@should] result = true else Puppet.debug "Creating checksum %s for %s of type %s" % - [self.is,self.parent[:path],@checktype] + [self.is,self.parent.name,@checktype] result = false end - state[self.parent[:path]][@checktype] = @is + state[self.parent.name][@checktype] = @is return result end end @@ -170,11 +245,14 @@ module Puppet begin Puppet.debug("Creating symlink '%s' to '%s'" % [file, link]) unless File.symlink(file,link) - raise TypeError.new("Could not create symlink '%s'" % link) + raise Puppet::Error.new( + "Could not create symlink '%s'" % link + ) end rescue => detail - raise TypeError.new("Cannot create symlink '%s': %s" % - [file,detail]) + raise Puppet::Error.new( + "Cannot create symlink '%s': %s" % [file,detail] + ) end end @@ -185,10 +263,14 @@ module Puppet begin File.unlink(link) rescue - raise TypeError.new("Failed to remove symlink '%s'" % link) + raise Puppet::Error.new( + "Failed to remove symlink '%s'" % link + ) end elsif FileTest.exists?(link) - raise TypeError.new("Cannot remove normal file '%s'" % link) + error = Puppet::Error.new( + "Cannot remove normal file '%s'" % link) + raise error else Puppet.debug("Symlink '%s' does not exist" % link) end @@ -237,7 +319,10 @@ module Puppet @event = :inode_changed def retrieve - stat = self.parent.stat(true) + unless stat = self.parent.stat(true) + @is = -1 + return + end self.is = stat.uid if defined? @should @@ -245,13 +330,18 @@ module Puppet begin user = Etc.getpwnam(@should) if user.gid == "" - raise "Could not retrieve uid for '%s'" % self.parent + error = Puppet::Error.new( + "Could not retrieve uid for '%s'" % + self.parent.name) + raise error end Puppet.debug "converting %s to integer '%d'" % [@should,user.uid] @should = user.uid - rescue - raise "Could not get any info on user '%s'" % @should + rescue => detail + error = Puppet::Error.new( + "Could not get any info on user '%s'" % @should) + raise error end end end @@ -274,8 +364,9 @@ module Puppet begin File.chown(self.should,-1,self.parent[:path]) rescue => detail - raise "failed to chown '%s' to '%s': %s" % - [self.parent[:path],self.should,detail] + error = Puppet::Error.new("failed to chown '%s' to '%s': %s" % + [self.parent[:path],self.should,detail]) + raise error end return :inode_changed @@ -325,8 +416,10 @@ module Puppet begin File.chmod(self.should,self.parent[:path]) - rescue - raise "failed to chmod #{self.parent[:path]}: #{$!}" + rescue => detail + error = Puppet::Error.new("failed to chmod %s: %s" % + [self.parent.name, detail.message]) + raise error end return :inode_changed end @@ -392,14 +485,17 @@ module Puppet gid = group.gid end if gid == "" - raise "Could not retrieve gid for %s" % self.parent + error = Puppet::Error.new( + "Could not retrieve gid for %s" % self.parent.name) + raise error end Puppet.debug "converting %s to integer %d" % [self.should,gid] self.should = gid - rescue - #raise "Could not get any info on group %s" % self.should - raise + rescue => detail + error = Puppet::Error.new( + "Could not get any info on group %s: %s" % self.should) + raise error end end end @@ -423,40 +519,377 @@ module Puppet begin # set owner to nil so it's ignored File.chown(nil,self.should,self.parent[:path]) - rescue - raise "failed to chgrp %s to %s: %s" % - [self.parent[:path], self.should, $!] + rescue => detail + error = Puppet::Error.new( "failed to chgrp %s to %s: %s" % + [self.parent[:path], self.should, detail.message]) + raise error end return :inode_changed end end + + class PFileSource < Puppet::State + attr_accessor :source, :local + + @name = :source + + def localshould=(value) + # in order to know if we need to sync, we need to compare our file's + # checksum to the source file's checksum + type = Puppet::Type.type(:file) + file = nil + + @source = value + # if the file is already being managed through some other mechanism... + if file = type[value] + error = Puppet::Error.new( + "Cannot currently use managed files (%s) as sources" % value) + raise error + else + self.parent.pin(@source) + end + end + + def retrieve + type = Puppet::Type.type(:file) + + stat = File.stat(@source) + case stat.ftype + when "file": + @should = type[@source].state(:checksum).is || -1 + @is = self.parent[:checksum] + when "directory": + error = Puppet::Error.new( + "Somehow got told to create dir %s" % self.parent.name) + raise error + else + error = Puppet::Error.new( + "Cannot use files of type %s as source" % stat.ftype) + raise error + end + end + + def should=(value) + lreg = Regexp.new("^file://") + oreg = Regexp.new("^(\s+)://") + + # if we're a local file... + if value =~ /^\// or value =~ lreg + @local = true + + # if they passed a uri instead of just a filename... + if value =~ lreg + value.sub(lreg,'') + unless value =~ /\// + error = Puppet::Error.new("Invalid file name: %s" % value) + raise error + end + end + + # XXX for now, only allow files that already exist + unless FileTest.exist?(value) + Puppet.err "Cannot use non-existent file %s as source" % + value + @should = nil + @nil = nil + return nil + end + elsif value =~ oreg + @local = false + + # currently, we only support local sources + error = Puppet::Error.new("No support for proto %s" % $1) + raise error + else + error = Puppet::Error.new("Invalid URI %s" % value) + raise error + end + + # if they haven't already specified a checksum type to us, then + # specify that we need to collect checksums and default to md5 + unless self.parent[:checksum] + self.parent[:checksum] = "md5" + end + + self.localshould = value + end + + def sync + # this method is kind of interesting + # we could choose to do this two ways: either directly + # compare and then copy over, as we currently are, or we could + # just define a 'refresh' method for this state and let the existing + # event mechanisms notify us when there's a change + + unless defined? @source + Puppet.err "No source set for %s" % self.parent.name + return nil + end + + unless FileTest.exists?(@source) + Puppet.err "Source %s does not exist -- cannot copy to %s" % + [@source, self.parent.name] + return nil + end + + if @should == -1 + Puppet.warning "Trying again for source checksum" + type = Puppet::Type.type(:file) + file = nil + + if file = type[@source] + @should = file.state(:checksum).is + if @should.nil? or @should == -1 + error = Puppet::Error.new( + "Could not retrieve checksum state for %s(%s)" % + [file.name,@should]) + raise error + end + else + error = Puppet::Error.new("%s is somehow not managed" % @source) + raise error + end + end + + if FileTest.file?(@source) + if bucket = self.parent[:filebucket] + bucket.backup(self.parent.name) + elsif str = self.parent[:backup] + # back the file up + begin + FileUtils.cp(self.parent.name, + self.parent.name + self.parent[:backup]) + rescue => detail + # since they said they want a backup, let's error out + # if we couldn't make one + error = Puppet::Error.new("Could not back %s up: %s" % + [self.parent.name, detail.message]) + raise error + end + end + end + + # okay, we've now got whatever backing up done we might need + # so just copy the files over + if @local + stat = File.stat(@source) + case stat.ftype + when "file": + begin + FileUtils.cp(@source, self.parent.name) + rescue => detail + # since they said they want a backup, let's error out + # if we couldn't make one + error = Puppet::Error.new("Could not copy %s to %s: %s" % + [@source, self.parent.name, detail.message]) + raise error + end + when "directory": + error = Puppet::Error.new( + "Somehow got told to sync directory %s" % + self.parent.name) + raise error + when "link": + dest = File.readlink(@source) + Puppet::State::PFileLink.create(@dest,self.parent.path) + else + error = Puppet::Error.new("Cannot use files of type %s as source" % + stat.ftype) + raise error + end + else + raise Puppet::Error.new("Somehow got a non-local source") + end + return :file_changed + end + end end class Type class PFile < Type - attr_reader :params + attr_reader :params, :source + # class instance variable @states = [ Puppet::State::PFileCreate, + Puppet::State::PFileSource, Puppet::State::PFileUID, Puppet::State::PFileGroup, Puppet::State::PFileMode, Puppet::State::PFileChecksum, Puppet::State::PFileSetUID, - Puppet::State::PFileLink, + Puppet::State::PFileLink ] @parameters = [ :path, - :recurse + :recurse, + :filebucket, + :backup ] @name = :file @namevar = :path + def initialize(hash) + arghash = hash.dup + super + + @stat = nil + + # if recursion is enabled and we're a directory... + if @parameters[:recurse] + if FileTest.exist?(self.name) and self.stat.directory? + self.recurse(arghash) + elsif @states.include?(:source) # uh, yeah, uh... + Puppet.err "Ugh!" + self.recurse(arghash) + else + Puppet.err "No recursion or source for %s" % self.name + end + end + + # yay, super-hack! + if @states.include?(:create) + if @states[:create].should == "directory" + if @states.include?(:source) + Puppet.warning "Deleting source for directory %s" % + self.name + @states.delete(:source) + end + + if @states.include?(:checksum) + Puppet.warning "Deleting checksum for directory %s" % + self.name + @states.delete(:checksum) + end + else + Puppet.info "Create is %s for %s" % + [@states[:create].should,self.name] + end + end + end + + # this is kind of equivalent to copying the actual file + def pin(path) + pinparams = [:owner, :group, :mode, :checksum] + + obj = Puppet::Type::PFile.new( + :name => path, + :check => pinparams + ) + obj.evaluate # XXX *shudder* + + # only copy the inode and content states, not all of the metastates + [:owner, :group, :mode].each { |state| + unless @states.include?(state) + # this copies the source's 'is' value to our 'should' + self[state] = obj[state] + end + } + + if FileTest.directory?(path) + self[:create] = "directory" + # see amazingly crappy hack in initialize() + #self.delete(:source) + Puppet.info "Not sourcing checksum of directory %s" % path + else + # checksums are, like, special + if @states.include?(:checksum) + if @states[:checksum].checktype == + obj.state(:checksum).checktype + @states[:checksum].should = obj[:checksum] + else + Puppet.warning "Source file '%s' checksum type '%s' is incompatible with destination file '%s' checksum type '%s'; defaulting to md5 for both" % + [obj.name, obj.state(:checksum).checktype, + self.name, self[:checksum].checktype] + + # and then, um, default to md5 for everyone? + unless @source.state[:checksum].checktype == "md5" + Puppet.warning "Changing checktype on %s to md5" % + file.name + @source.state[:checksum].should = "md5" + end + + unless @states[:ckecksum].checktype == "md5" + Puppet.warning "Changing checktype on %s to md5" % + self.name + @states[:ckecksum].should = "md5" + end + end + else + self[:checksum] = obj.state(:checksum).checktype + @states[:checksum].should = obj[:checksum] + end + end + end + + def recurse(arghash) + Puppet.err "Recursing!" + recurse = self[:recurse] + # we might have a string, rather than a number + if recurse.is_a?(String) + if recurse =~ /^[0-9]+$/ + recurse = Integer(recurse) + elsif recurse =~ /^inf/ # infinite recursion + recurse = true + end + end + + # unless we're at the end of the recursion + if recurse != 0 + arghash.delete("recurse") + if recurse.is_a?(Integer) + recurse -= 1 # reduce the level of recursion + end + + arghash[:recurse] = recurse + + # now make each contained file/dir a child + unless defined? @children + @children = [] + end + + # make sure we don't have any remaining ':name' params + self.nameclean(arghash) + + Dir.foreach(self.name) { |file| + next if file =~ /^\.\.?/ # skip . and .. + + arghash[:path] = File.join(self.name,file) + + child = nil + # if the file already exists... + if child = self.class[arghash[:path]] + arghash.each { |var,value| + next if var == :path + child[var] = value + } + else # create it anew + #notice "Creating new file with args %s" % + # arghash.inspect + child = self.class.new(arghash) + end + @children.push child + } + end + end + + # I don't currently understand the problems of dependencies in this space + # to know how to handle having 'refresh' called here +# def refresh +# unless @states.include?(:source) +# return nil +# end +# +# self.pin(@states[:source].source) +# +# self.retrieve +# end + # a wrapper method to make sure the file exists before doing anything def retrieve unless stat = self.stat(true) - Puppet.debug "PFile %s does not exist" % self[:path] + Puppet.debug "File %s does not exist" % self[:path] @states.each { |name,state| state.is = -1 } @@ -478,64 +911,6 @@ module Puppet return @stat end - - def initialize(hash) - arghash = hash.dup - super - @stat = nil - - # if recursion is enabled and we're a directory... - if @parameters[:recurse] and FileTest.exist?(self.name) and - self.stat.directory? - recurse = self[:recurse] - # we might have a string, rather than a number - if recurse.is_a?(String) - if recurse =~ /^[0-9]+$/ - recurse = Integer(recurse) - elsif recurse =~ /^inf/ # infinite recursion - recurse = true - end - end - - # unless we're at the end of the recursion - if recurse != 0 - arghash.delete("recurse") - if recurse.is_a?(Integer) - recurse -= 1 # reduce the level of recursion - end - - arghash[:recurse] = recurse - - # now make each contained file/dir a child - unless defined? @children - @children = [] - end - - # make sure we don't have any remaining ':name' params - self.nameclean(arghash) - - Dir.foreach(self.name) { |file| - next if file =~ /^\.\.?/ # skip . and .. - - arghash[:path] = File.join(self.name,file) - - child = nil - # if the file already exists... - if child = self.class[arghash[:path]] - arghash.each { |var,value| - next if var == :path - child[var] = value - } - else # create it anew - #notice "Creating new file with args %s" % - # arghash.inspect - child = self.class.new(arghash) - end - @children.push child - } - end - end - end end # Puppet::Type::PFile end # Puppet::Type diff --git a/lib/puppet/type/service.rb b/lib/puppet/type/service.rb index ce7a07cbb..a824225fc 100644 --- a/lib/puppet/type/service.rb +++ b/lib/puppet/type/service.rb @@ -144,20 +144,8 @@ module Puppet def setpath(ary) # verify each of the paths exists - #ary.flatten! @searchpaths = ary.find_all { |dir| - retvalue = false - begin - retvalue = File.stat(dir).directory? - rescue => detail - debug("Directory %s does not exist: %s" % [dir,detail]) - # just ignore it - end - # disallow relative paths - #if dir !~ /^\// - # retvalue = false - #end - retvalue + FileTest.directory?(dir) } end |
