fix: save config + manifests by first writing them to another file and moving them over

Should hopefully make corrupted configs a bit more rare
This commit is contained in:
goat 2023-03-19 13:11:27 +01:00
parent 111eea290c
commit 86181cd2d4
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
4 changed files with 22 additions and 6 deletions

View file

@ -568,6 +568,22 @@ public static class Util
}
}
/// <summary>
/// Overwrite text in a file by first writing it to a temporary file, and then
/// moving that file to the path specified.
/// </summary>
/// <param name="path">The path of the file to write to.</param>
/// <param name="text">The text to write.</param>
internal static void WriteAllTextSafe(string path, string text)
{
var tmpPath = path + ".tmp";
if (File.Exists(tmpPath))
File.Delete(tmpPath);
File.WriteAllText(tmpPath, text);
File.Move(tmpPath, path, true);
}
private static unsafe void ShowValue(ulong addr, IEnumerable<string> path, Type type, object value)
{
if (type.IsPointer)