lib/puppet/provider/parsedfile.rb in puppet-0.23.0 vs lib/puppet/provider/parsedfile.rb in puppet-0.23.1
- old
+ new
@@ -117,10 +117,19 @@
# Override the default method with a lot more functionality.
def self.mk_resource_methods
[resource_type.validproperties, resource_type.parameters].flatten.each do |attr|
attr = symbolize(attr)
define_method(attr) do
+# if @property_hash.empty?
+# # Note that this swaps the provider out from under us.
+# prefetch()
+# if @resource.provider == self
+# return @property_hash[attr]
+# else
+# return @resource.provider.send(attr)
+# end
+# end
# If it's not a valid field for this record type (which can happen
# when different platforms support different fields), then just
# return the should value, so the resource shuts up.
if @property_hash[attr] or self.class.valid_attr?(self.class.name, attr)
@property_hash[attr] || :absent
@@ -177,17 +186,23 @@
targets(resources).each do |target|
@records += prefetch_target(target)
end
if resources
+ matchers = resources.dup
@records.each do |record|
+ # Skip things like comments and blank lines
+ next if record_type(record[:record_type]).text?
+
if name = record[:name] and resource = resources[name]
resource.provider = new(record)
elsif respond_to?(:match)
- if instance = match(record, resources)
- record[:name] = instance[:name]
- instance.provider = new(record)
+ if resource = match(record, matchers)
+ # Remove this resource from circulation so we don't unnecessarily try to match
+ matchers.delete(resource.title)
+ record[:name] = resource[:name]
+ resource.provider = new(record)
end
end
end
end
end
@@ -227,11 +242,14 @@
else
# Set the target, for logging.
old = @target
begin
@target = path
- self.parse(text)
+ return self.parse(text)
+ rescue Puppet::Error => detail
+ detail.file = @target
+ raise detail
ensure
@target = old
end
end
end
@@ -262,11 +280,13 @@
targets += @target_objects.keys
# Lastly, check the file from any resource instances
if resources
resources.each do |name, resource|
- targets << resource.value(:target)
+ if value = resource.should(:target)
+ targets << value
+ end
end
end
targets.uniq.compact
end
@@ -312,10 +332,12 @@
self.class.modified(@property_hash[:target])
end
@property_hash[:name] ||= @resource.name
self.class.flush(@property_hash)
+
+ #@property_hash = {}
end
def initialize(resource)
super
@@ -325,8 +347,16 @@
# override it if the thing exists, but it won't touch it if it doesn't
# exist.
@property_hash = self.class.record?(resource[:name]) ||
{:record_type => self.class.name, :ensure => :absent}
end
+
+ # Retrieve the current state from disk.
+ def prefetch
+ unless @resource
+ raise Puppet::DevError, "Somehow got told to prefetch with no resource set"
+ end
+ self.class.prefetch(@resource[:name] => @resource)
+ end
end
-# $Id: parsedfile.rb 2551 2007-06-04 20:37:14Z luke $
+# $Id: parsedfile.rb 2722 2007-07-20 16:27:44Z luke $