Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct logic for DEFAULT config section population #590

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/590.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent Sydent from overwriting user settings in the DEFAULT section upon startup.
15 changes: 8 additions & 7 deletions sydent/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ def parse_config_file(self, config_file: str) -> None:

:param config_file: the file to be parsed
"""
# If the config file doesn't exist, prepopulate the config object
# with the defaults, in the right section.
# If the config file already exists, place all config options in
# the DEFAULT section, to avoid overriding any of the user's
# configured values in the sections other than DEFAULT.
#
# Otherwise, we have to put the defaults in the DEFAULT section,
# to ensure that they don't override anyone's settings which are
# in their config file in the default section (which is likely,
# because sydent used to be braindead).
use_defaults = not os.path.exists(config_file)
# We don't always do this as earlier Sydent versions required
# users to put their settings in the DEFAULT section.
#
# We want to avoid overwriting those.
use_defaults = os.path.exists(config_file)

cfg = ConfigParser()
for sect, entries in CONFIG_DEFAULTS.items():
Expand Down
Loading