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

Improve safety of mod configuration save #97

@zkxs

Description

@zkxs

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestup for grabsUncle Sam wants YOU to resolve this issue!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions