Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Improve safety of mod configuration save #97

Open
zkxs opened this issue Apr 16, 2023 · 0 comments
Open

Improve safety of mod configuration save #97

zkxs opened this issue Apr 16, 2023 · 0 comments
Labels
enhancement New feature or request up for grabs Uncle Sam wants YOU to resolve this issue!

Comments

@zkxs
Copy link
Collaborator

zkxs commented Apr 16, 2023

Currently, NML nukes the existing mod configuration file as it writes a new one. If something goes wrong, this can result in an empty or partially written file. Relevant code here.

If this fails it's a pretty bad experience for the user, as NML will have all sorts of errors trying to load the broken configs, so not only has the user lost their configuration, they've also got to go manually delete the broken files.

This configuration save process could be made much more robust by writing to an intermediate file and then only on success copying that over the real config file. For example, using a temporary MyMod.tmp.json file:

  1. Delete MyMod.tmp.json if it exists
  2. Write new config to MyMod.tmp.json
  3. Optionally, verify that MyMod.tmp.json is contains valid JSON
  4. Delete MyMod.json
  5. Move MyMod.tmp.json to MyMod.json

There may be other ways of doing this—I've just suggested one possibility. For example, if C# has an API somewhere that can atomically replace an existing file (like a unix-style mv) that'd be even better.

@zkxs zkxs added enhancement New feature or request up for grabs Uncle Sam wants YOU to resolve this issue! labels Apr 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request up for grabs Uncle Sam wants YOU to resolve this issue!
Projects
None yet
Development

No branches or pull requests

1 participant