Skip to content

Commit c1ff630

Browse files
committed
Merge pull request #321 from cyberious/4.3.x
MODULES-1248 Fix issue with not properly counting regex matches with leg...
2 parents 4a79fd0 + acf435d commit c1ff630

File tree

1 file changed

+6
-4
lines changed
  • lib/puppet/provider/file_line

1 file changed

+6
-4
lines changed

lib/puppet/provider/file_line/ruby.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def lines
3434

3535
def handle_create_with_match()
3636
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
37-
match_count = lines.select { |l| regex.match(l) }.size
37+
match_count = count_matches(regex)
3838
if match_count > 1 && resource[:multiple].to_s != 'true'
3939
raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
4040
end
@@ -51,9 +51,7 @@ def handle_create_with_match()
5151

5252
def handle_create_with_after
5353
regex = Regexp.new(resource[:after])
54-
55-
count = lines.count {|l| l.match(regex)}
56-
54+
count = count_matches(regex)
5755
case count
5856
when 1 # find the line to put our line after
5957
File.open(resource[:path], 'w') do |fh|
@@ -71,6 +69,10 @@ def handle_create_with_after
7169
end
7270
end
7371

72+
def count_matches(regex)
73+
lines.select{|l| l.match(regex)}.size
74+
end
75+
7476
##
7577
# append the line to the file.
7678
#

0 commit comments

Comments
 (0)