Skip to content

file: drop removed keys and sections on Reload - #419

Open
rhmatzeka wants to merge 1 commit into
go-ini:mainfrom
rhmatzeka:fix/reload-drop-removed-keys
Open

rhmatzeka wants to merge 1 commit into
go-ini:mainfrom
rhmatzeka:fix/reload-drop-removed-keys

Conversation

@rhmatzeka

Copy link
Copy Markdown

Describe the pull request

File.Reload() parsed every data source on top of the sections already in memory, so nothing that had been removed from the source ever went away:

  • a key deleted from the file was still there after Reload() (the case in Reload retains keys removed from the source file #418);
  • a whole section deleted from the file was still there too;
  • with AllowNonUniqueSections, every Reload() appended another copy of every section, DEFAULT included ([DEFAULT peer peer] → [DEFAULT peer peer DEFAULT peer peer]).

Reload() now clears the sections before parsing the sources again, so the result matches what loading the sources from scratch gives. The parsing loop moved into an unexported loadSources(), which Append() keeps calling as before, so Append() still merges on top of the current sections and anything created in memory before an Append() is not lost.

The only behaviour change is that Reload() now discards in-memory edits, which matches what reloading means; the doc comment says so.

Link to the issue: #418

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code.

Tests: TestReloadDropsRemovedKeysAndSections and TestReloadDoesNotDuplicateNonUniqueSections fail before the change and pass after it. go test -race ./... and go vet ./... pass, and the existing TestReloadAfterShadowLoad (#207) still passes.

Reload parsed every data source on top of the sections already in
memory, so a key or section deleted from the source stayed around after
a reload, and with AllowNonUniqueSections every reload appended another
copy of each section. Reload now clears the sections before parsing.

Append keeps merging on top of the current sections, so sections created
in memory before Append are not lost.

Fixes go-ini#418

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant