From 6d65e68e29b42210fad7f47c138720b0a8e35377 Mon Sep 17 00:00:00 2001 From: Archangel Date: Mon, 13 Oct 2025 15:34:46 +0200 Subject: [PATCH] Add comments --- Libraries/SPTarkov.Server.Core/Utils/FileUtil.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Libraries/SPTarkov.Server.Core/Utils/FileUtil.cs b/Libraries/SPTarkov.Server.Core/Utils/FileUtil.cs index 65eee9fa..8a961dbb 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/FileUtil.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/FileUtil.cs @@ -106,6 +106,10 @@ public class FileUtil await WriteFileAsync(filePath, bytes); } + /// + /// Writes a file atomically by first writing to a temporary file, then replacing the original. + /// This prevents corruption if the write operation fails or is interrupted. + /// public async Task WriteFileAsync(string filePath, byte[] fileContent) { var directoryPath = Path.GetDirectoryName(filePath); @@ -124,9 +128,12 @@ public class FileUtil ) { await fs.WriteAsync(fileContent); + + // We flush here so we can be sure it's immediately committed to disk await fs.FlushAsync(); } + // Overwrite over the old file File.Move(tempFilePath, filePath, overwrite: true); } catch