From 42ab73f29ada8e045e6638ccb454b12595220fe1 Mon Sep 17 00:00:00 2001 From: Markus Roberts Date: Fri, 4 Sep 2009 16:10:20 -0700 Subject: Ticket #2525 don't fail find_manifest on invalid module names The patch that put validity assertions in for module names broke find_manifest because rather than returning a failure it now rasies an exception. This patch catches the exception and treats it as a negative result. Signed-off-by: Markus Roberts --- lib/puppet/parser/files.rb | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'lib/puppet/parser') diff --git a/lib/puppet/parser/files.rb b/lib/puppet/parser/files.rb index 749428e9f..3442e11a6 100644 --- a/lib/puppet/parser/files.rb +++ b/lib/puppet/parser/files.rb @@ -16,10 +16,13 @@ module Puppet::Parser::Files def find_manifests(start, options = {}) cwd = options[:cwd] || Dir.getwd module_name, pattern = split_file_path(start) - if mod = Puppet::Module.find(module_name, options[:environment]) - return mod.match_manifests(pattern) + begin + if mod = Puppet::Module.find(module_name, options[:environment]) + return mod.match_manifests(pattern) + end + rescue Puppet::Module::InvalidName + # Than that would be a "no." end - abspat = File::expand_path(start, cwd) files = Dir.glob(abspat).reject { |f| FileTest.directory?(f) } if files.size == 0 @@ -79,16 +82,11 @@ module Puppet::Parser::Files end end - # Split the path into the module and the rest of the path. - # This method can and often does return nil, so anyone calling - # it needs to handle that. + # Split the path into the module and the rest of the path, or return + # nil if the path is empty or absolute (starts with a /). + # This method can return nil & anyone calling it needs to handle that. def split_file_path(path) - if path =~ %r/^#{File::SEPARATOR}/ - return nil - end - - modname, rest = path.split(File::SEPARATOR, 2) - return nil if modname.nil? || modname.empty? - return modname, rest + path.split(File::SEPARATOR, 2) unless path =~ /^(#{File::SEPARATOR}|$)/ end + end -- cgit