Prevent spurious diffs in config file by sorting Client objects before writing #3933
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to prevent occasional reordering diffs like the following from appearing in the
AdGuardHome.yaml
config file:This is problematic when including the config file in version control, since occasional no-op changes pop up and require reverting/committing.
I think the root cause of these reorders is that Go doesn't guarantee a consistent iteration order over maps (see the "Iteration order" section of https://go.dev/blog/maps), so e.g. different executions of an adguard docker container/daemon will produce different orders. By sorting the list of objects we create from the map before outputting them, we guarantee clients will be ordered by name.
I've only noticed this being an issue for the
clients
section of the config file: I haven't done a deep dive into the other config file fields, but from a quick skim of my config it looks they're probably not stored in maps so don't see this behaviour.