Skip to content

Commit

Permalink
(CAT-1646) - Remove section if its not have any settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramesh7 committed Mar 7, 2024
1 parent 94a3c57 commit 42cfdb1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/puppet/util/ini_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def parse_file
def read_section(name, start_line, line_iter)
settings = {}
end_line_num = start_line
previous_line = nil
min_indentation = nil
empty = true
loop do
Expand All @@ -229,14 +230,22 @@ def read_section(name, start_line, line_iter)
# when it's empty, we must be sure it's thought of as new,
# which is signalled with a nil ending line
end_line_num = nil if name == '' && empty
end_line_num = line_num - 1 if previous_line == "\n"
return Section.new(name, start_line, end_line_num, settings, min_indentation)
end
if (match = @setting_regex.match(line))
settings[match[2]] = match[4]
indentation = match[1].length
min_indentation = [indentation, min_indentation || indentation].min
end
end_line_num = line_num
# If we have a comment line, we need to remember it so that
# we can insert new settings *before* the comment line.
if line != "\n"
end_line_num = line_num
previous_line = nil
else
previous_line = line
end
empty = false
line_iter.next
end
Expand Down

0 comments on commit 42cfdb1

Please sign in to comment.