diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-04 21:06:26 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-07-04 21:06:26 +0000 |
commit | 0ff7827d4d7f42fe59c10af35266f197e83b2b17 (patch) | |
tree | de9f74e509a7ed8d8be76f937445569fca184242 /lib | |
parent | a627f467f0455281ce7fbe4690b7b408fbe80f82 (diff) | |
download | puppet-0ff7827d4d7f42fe59c10af35266f197e83b2b17.tar.gz puppet-0ff7827d4d7f42fe59c10af35266f197e83b2b17.tar.xz puppet-0ff7827d4d7f42fe59c10af35266f197e83b2b17.zip |
Fixing #620 - class names and node names now throw an error when they conflict
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2646 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/scope.rb | 30 |
2 files changed, 22 insertions, 10 deletions
diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index 5416c1071..642645824 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -25,7 +25,7 @@ class Puppet::Parser::AST args = hash[:arguments] # Verify that we haven't already been evaluated - if scope.setclass?(self) + if scope.class_scope(self) Puppet.debug "%s class already evaluated" % @type return nil end diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index c67825bb3..6feeefc46 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -115,11 +115,19 @@ class Puppet::Parser::Scope # that subclasses can set their parent scopes to be the scope of # their parent class. def class_scope(klass) - if klass.respond_to?(:classname) + scope = if klass.respond_to?(:classname) @classtable[klass.classname] else @classtable[klass] end + + return nil unless scope + + if scope.nodescope? and ! klass.is_a?(AST::Node) + raise Puppet::ParseError, "Node %s has already been evaluated; cannot evaluate class with same name" % [klass.classname] + end + + scope end # Return the list of collections. @@ -442,6 +450,14 @@ class Puppet::Parser::Scope return Puppet::Parser::Scope.new(hash) end + # Is this class for a node? This is used to make sure that + # nodes and classes with the same name conflict (#620), which + # is required because of how often the names are used throughout + # the system, including on the client. + def nodescope? + defined?(@nodescope) and @nodescope + end + # Return the list of remaining overrides. def overrides #@overridetable.collect { |name, overs| overs }.flatten @@ -452,14 +468,6 @@ class Puppet::Parser::Scope @definedtable.values end - def setclass?(obj) - if obj.respond_to?(:classname) - @classtable.has_key?(obj.classname) - else - @classtable[obj] - end - end - # Store the fact that we've evaluated a given class. We use a hash # that gets inherited from the top scope down, rather than a global # hash. We store the object ID, not class name, so that we @@ -474,6 +482,10 @@ class Puppet::Parser::Scope else raise Puppet::DevError, "Invalid class %s" % obj.inspect end + if obj.is_a?(AST::Node) + @nodescope = true + end + nil end # Set all of our facts in the top-level scope. |