Class AtomicTextFile
- Namespace
- McServerLauncher.Services
- Assembly
- McServerLauncher.dll
Writing a config file the app owns: only when it actually changed, and never half-written.
public static class AtomicTextFile
- Inheritance
-
AtomicTextFile
- Inherited Members
Remarks
Both halves earn their place. Geyser's config.yml is rewritten by the address refresh
every thirty seconds for as long as the server runs, and an unconditional
WriteAllText(string, string) there means the file is destroyed and recreated a
hundred and twenty times an hour to end up byte-for-byte identical — which also turns any bug in
what is written into something that reaches disk on its own, with nobody touching anything.
And the write goes through a temporary file for the same reason AtomicJsonFile does: cut the power in the middle of the direct version and the server is left with a truncated config that Geyser cannot parse.
Methods
WriteIfChanged(string, string)
Writes text to path unless it is already there.
public static bool WriteIfChanged(string path, string text)
Parameters
Returns
- bool
True when the file was written, false when it already said exactly this.