From acf435d1ce5916f99a13ef12f5f6560c9e63b935 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 16 Sep 2014 10:46:19 -0700 Subject: MODULES-1248 Fix issue with not properly counting regex matches with legacy versions of ruby --- lib/puppet/provider/file_line/ruby.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index 94e7fac..ae1a8b3 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -34,7 +34,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do def handle_create_with_match() regex = resource[:match] ? Regexp.new(resource[:match]) : nil - match_count = lines.select { |l| regex.match(l) }.size + match_count = count_matches(regex) if match_count > 1 && resource[:multiple].to_s != 'true' raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" end @@ -51,9 +51,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do def handle_create_with_after regex = Regexp.new(resource[:after]) - - count = lines.count {|l| l.match(regex)} - + count = count_matches(regex) case count when 1 # find the line to put our line after File.open(resource[:path], 'w') do |fh| @@ -71,6 +69,10 @@ Puppet::Type.type(:file_line).provide(:ruby) do end end + def count_matches(regex) + lines.select{|l| l.match(regex)}.size + end + ## # append the line to the file. # -- cgit v1.2.3 From 8ad7f68ecaf444b39c4ca89e2e62790bc00ad89a Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Wed, 8 Oct 2014 10:14:10 -0700 Subject: ENTERPRISE-281 fixes issue with has_interfaces and case mismatch causing us not to return some interfaces --- lib/puppet/parser/functions/has_interface_with.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/puppet') diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index 927b0df..d5dbe47 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -34,13 +34,15 @@ has_interface_with("lo") => true end kind, value = args - + kind.downcase! + if lookupvar(kind) == value return true end result = false interfaces.each do |iface| + iface.downcase! if value == lookupvar("#{kind}_#{iface}") result = true break -- cgit v1.2.3