Skip to content

Commit 54a1732

Browse files
committed
Revert "(CAT-1646) - Remove section if its not have any settings"
PR #532 introduced 4ebe030 breaks backwards compatibility and is part of a patch release, as stated here: #532 (comment) This reverts commit 4ebe030. This will allow us to do a new patch release that fix the unexpected backwards incompatible change, and leave the room to implement this as part of a next major version of the module.
1 parent a28847c commit 54a1732

File tree

3 files changed

+3
-39
lines changed

3 files changed

+3
-39
lines changed

lib/puppet/util/ini_file.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,21 @@ def read_section(name, start_line, line_iter)
222222
end_line_num = start_line
223223
min_indentation = nil
224224
empty = true
225-
empty_line_count = 0
226225
loop do
227226
line, line_num = line_iter.peek
228227
if line_num.nil? || @section_regex.match(line)
229228
# the global section always exists, even when it's empty;
230229
# when it's empty, we must be sure it's thought of as new,
231230
# which is signalled with a nil ending line
232231
end_line_num = nil if name == '' && empty
233-
return Section.new(name, start_line, end_line_num, settings, min_indentation, empty_line_count)
232+
return Section.new(name, start_line, end_line_num, settings, min_indentation)
234233
end
235234
if (match = @setting_regex.match(line))
236235
settings[match[2]] = match[4]
237236
indentation = match[1].length
238237
min_indentation = [indentation, min_indentation || indentation].min
239238
end
240239
end_line_num = line_num
241-
empty_line_count += 1 if line == "\n"
242-
243240
empty = false
244241
line_iter.next
245242
end

lib/puppet/util/ini_file/section.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ class Section
1414
# `end_line` of `nil`.
1515
# * `start_line` and `end_line` will be set to `nil` for a new non-global
1616
# section.
17-
def initialize(name, start_line, end_line, settings, indentation, empty_line_count = 0)
17+
def initialize(name, start_line, end_line, settings, indentation)
1818
@name = name
1919
@start_line = start_line
2020
@end_line = end_line
2121
@existing_settings = settings.nil? ? {} : settings
2222
@additional_settings = {}
2323
@indentation = indentation
24-
@empty_line_count = empty_line_count
2524
end
2625

2726
attr_reader :name, :start_line, :end_line, :additional_settings, :indentation
@@ -51,7 +50,7 @@ def existing_setting?(setting_name)
5150
# the global section is empty whenever it's new;
5251
# other sections are empty when they have no lines
5352
def empty?
54-
global? ? new_section? : (start_line == end_line || (end_line && (end_line - @empty_line_count)) == start_line)
53+
global? ? new_section? : start_line == end_line
5554
end
5655

5756
def update_existing_setting(setting_name, value)

spec/unit/puppet/provider/ini_setting/ruby_spec.rb

-32
Original file line numberDiff line numberDiff line change
@@ -1141,38 +1141,6 @@ def self.file_path
11411141
end
11421142
end
11431143

1144-
context 'when section has only empty line' do
1145-
let(:orig_content) do
1146-
<<~INIFILE
1147-
[section1]
1148-
foo=foovalue
1149-
1150-
1151-
[section2]
1152-
1153-
foo= foovalue2
1154-
baz=bazvalue
1155-
url = http://
1156-
INIFILE
1157-
end
1158-
1159-
expected_content = <<~INIFILE
1160-
[section2]
1161-
1162-
foo= foovalue2
1163-
baz=bazvalue
1164-
url = http://
1165-
INIFILE
1166-
1167-
it 'remove empty section' do
1168-
resource = Puppet::Type::Ini_setting.new(common_params.merge(section: 'section1', setting: 'foo', ensure: 'absent'))
1169-
provider = described_class.new(resource)
1170-
expect(provider.exists?).to be true
1171-
provider.destroy
1172-
validate_file(expected_content, tmpfile)
1173-
end
1174-
end
1175-
11761144
context 'when dealing with indentation in sections' do
11771145
let(:orig_content) do
11781146
<<~INIFILE

0 commit comments

Comments
 (0)