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

Core: save default settings before opening file for users #4042

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

qwint
Copy link
Contributor

@qwint qwint commented Oct 9, 2024

What is this fixing or adding?

saves the settings before opening host.yaml so all defaults are populated

How was this tested?

had an outdated host.yaml for TUNIC, installed the new one, clicked the open host.yaml button in the launcher, saw the new settings values populated

If this makes graphical changes, please attach screenshots.

@github-actions github-actions bot added affects: core Issues/PRs that touch core and may need additional validation. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet. labels Oct 9, 2024
@Exempt-Medic Exempt-Medic added the is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. label Oct 10, 2024
@Jouramie
Copy link
Contributor

Shouldn't settings.get_settings handle that? Since it already saves the file if it does not exist, I think it would make sense if the function would also update if when it's missing default properties. With the current changes, the file will be saved two times if it didn't exist.

@qwint
Copy link
Contributor Author

qwint commented Oct 14, 2024

oh nice catch,
my worry though about moving it upstream to get_settings is when do you choose to save or not?
do you iterate every key to see if there is any key missing? do you pass in an optional parameter?
most get_settings calls do not care about the contents of the file and are happy to just pull back defaults if the file is missing info, and some even intend to update and save some data meaning you'd be double saving in those cases instead of in this case

I'd be happy if you had a solution to these worries 😅 but I don't so I'm personally content with some redundant saving on a user action

@Jouramie
Copy link
Contributor

Jouramie commented Oct 15, 2024

The more I look at get_settings, the more I think that the fact that it can save is an undesirable side effect in most cases. This function does two things, it should only do one, accessing the current settings (not saving them). As you said, in most cases, callers are happy with just the values and don't need the actual file to be up-to-date. It's only in the case where we actually want to open or modify the settings that it needs to be saved.

That being said, changing that seems like a medium size and maybe impacting refactor. I've checked only a handful of the calls and have no idea if it would impact something to move the save out of get_settings. All things considered, the unnecessary save seems pretty harmless.

@qwint
Copy link
Contributor Author

qwint commented Oct 15, 2024

so is that an approval? 😅

@black-sliver
Copy link
Member

I said something alone those lines in discord:

get_settings() is not supposed to save.
atexit hook is supposed to save if and only if the file will be changed.
The biggest reason for that is the race when you open multiple AP programs.
The reason why we can create a file if it doesn't exist yet, is because that is most likely safe. Multiple programs opened at the same time in a racy fashion would save identical files.

So, the solution presented in this PR is mostly correct - you only safe if the user explicitly asks to have the current file.
The thing this PR gets "wrong" is that it also saves if it hasn't changed, however the world cache to detect if saving would be required or not does not exist yet, so this is a good stop gap.

Copy link
Member

@black-sliver black-sliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@black-sliver black-sliver merged commit 79cec89 into ArchipelagoMW:main Oct 16, 2024
18 checks passed
@qwint qwint deleted the settings_save branch October 16, 2024 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects: core Issues/PRs that touch core and may need additional validation. is: bug/fix Issues that are reporting bugs or pull requests that are fixing bugs. waiting-on: peer-review Issue/PR has not been reviewed by enough people yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants