summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-02 19:04:40 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-09-02 19:04:40 +0000
commit96350b20cd2e6b651dc9f488a9ab7b319f6b8f57 (patch)
treef0fa3c8aa4dc47041e08278bc2aa253938b6dbdc /lib
parent114debdd0eb872b40e8b7d9019e62c5010617afa (diff)
downloadpuppet-96350b20cd2e6b651dc9f488a9ab7b319f6b8f57.tar.gz
puppet-96350b20cd2e6b651dc9f488a9ab7b319f6b8f57.tar.xz
puppet-96350b20cd2e6b651dc9f488a9ab7b319f6b8f57.zip
Fixing #257, where host aliases were not being retained. The problem was that the "should" method was returning an empty array if it was not set, and it should instead return nil.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1529 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rwxr-xr-xlib/puppet/type/parsedtype.rb53
-rwxr-xr-xlib/puppet/type/parsedtype/host.rb2
2 files changed, 33 insertions, 22 deletions
diff --git a/lib/puppet/type/parsedtype.rb b/lib/puppet/type/parsedtype.rb
index 0bb4353ef..b0e5f618d 100755
--- a/lib/puppet/type/parsedtype.rb
+++ b/lib/puppet/type/parsedtype.rb
@@ -107,7 +107,9 @@ module Puppet
class ParsedType < Puppet::Type
@name = :parsedtype
class << self
- attr_accessor :filetype, :hostfile, :fileobj, :fields, :path
+ attr_accessor :filetype, :hostfile, :fields
+ attr_reader :path
+ attr_writer :fileobj
end
# Override 'newstate' so that all states default to having the
@@ -145,6 +147,13 @@ module Puppet
super
end
+ # Initialize the object if necessary.
+ def self.fileobj
+ @fileobj ||= @filetype.new(@path)
+
+ @fileobj
+ end
+
# Return the header placed at the top of each generated file, warning
# users that modifying this file manually is probably a bad idea.
def self.header
@@ -153,14 +162,6 @@ module Puppet
# HEADER: is definitely not recommended.\n}
end
- # Parse a file
- #
- # Subclasses must override this method.
- def self.parse(text)
- raise Puppet::DevError, "Parse was not overridden in %s" %
- self.name
- end
-
# Convert the hash to an object.
def self.hash2obj(hash)
obj = nil
@@ -215,11 +216,30 @@ module Puppet
end
end
+ # Return the last time the file was loaded. Could
+ # be used for reducing writes, but currently is not.
+ def self.loaded?(user)
+ fileobj().loaded
+ end
+
+ # Parse a file
+ #
+ # Subclasses must override this method.
+ def self.parse(text)
+ raise Puppet::DevError, "Parse was not overridden in %s" %
+ self.name
+ end
+
+ # If they change the path, we need to get rid of our cache object
+ def self.path=(path)
+ @fileobj = nil
+ @path = path
+ end
+
# Retrieve the text for the file. Returns nil in the unlikely
# event that it doesn't exist.
def self.retrieve
- @fileobj ||= @filetype.new(@path)
- text = @fileobj.read
+ text = fileobj.read
if text.nil? or text == ""
# there is no file
return nil
@@ -238,8 +258,6 @@ module Puppet
# Write out the file.
def self.store
- @fileobj ||= @filetype.new(@path)
-
# Make sure all of our instances are in the to-be-written array
self.each do |inst|
@instances << inst unless @instances.include? inst
@@ -248,7 +266,7 @@ module Puppet
if @instances.empty?
Puppet.notice "No %s instances for %s" % [self.name, @path]
else
- @fileobj.write(self.to_file())
+ fileobj.write(self.to_file())
end
end
@@ -278,13 +296,6 @@ module Puppet
end
end
- # Return the last time the file was loaded. Could
- # be used for reducing writes, but currently is not.
- def self.loaded?(user)
- @fileobj ||= @filetype.new(@path)
- @fileobj.loaded
- end
-
# The 'store' method knows how to handle absence vs. presence
def create
self.store
diff --git a/lib/puppet/type/parsedtype/host.rb b/lib/puppet/type/parsedtype/host.rb
index 548ba543a..00cfe7857 100755
--- a/lib/puppet/type/parsedtype/host.rb
+++ b/lib/puppet/type/parsedtype/host.rb
@@ -41,7 +41,7 @@ module Puppet
return @should
end
else
- return []
+ return nil
end
end