From d15985e918d3559bab0812e1be9b411d65729abe Mon Sep 17 00:00:00 2001 From: zznty <94796179+zznty@users.noreply.github.com> Date: Sat, 9 Nov 2024 19:06:10 +0700 Subject: [PATCH] ensure restart save is exclusive to prevent save corruption --- Torch.API/Session/GameSaveResult.cs | 7 ++++++- Torch.Server/TorchServer.cs | 2 +- Torch/TorchBase.cs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Torch.API/Session/GameSaveResult.cs b/Torch.API/Session/GameSaveResult.cs index 836f884..3ce8d81 100644 --- a/Torch.API/Session/GameSaveResult.cs +++ b/Torch.API/Session/GameSaveResult.cs @@ -33,6 +33,11 @@ /// /// The save operation timed out /// - TimedOut = -5 + TimedOut = -5, + + /// + /// Another save operation is in progress + /// + ConcurrentSaveInProgress = -6 } } \ No newline at end of file diff --git a/Torch.Server/TorchServer.cs b/Torch.Server/TorchServer.cs index 2fb9c90..4626633 100644 --- a/Torch.Server/TorchServer.cs +++ b/Torch.Server/TorchServer.cs @@ -248,7 +248,7 @@ namespace Torch.Server { if (save) { - var saveResult = Save().Result; + var saveResult = Save(exclusive: true).Result; if (saveResult is not (GameSaveResult.Success or GameSaveResult.TimedOut)) { Log.Error("Save failed due to {Reason}. Restart aborted!", saveResult); diff --git a/Torch/TorchBase.cs b/Torch/TorchBase.cs index 4f833ce..1430bd1 100644 --- a/Torch/TorchBase.cs +++ b/Torch/TorchBase.cs @@ -330,7 +330,7 @@ namespace Torch if (MyAsyncSaving.InProgress || _inProgressSaves > 0) { Log.Error("Failed to save game, game is already saving"); - return null; + return Task.FromResult(GameSaveResult.ConcurrentSaveInProgress); } }