ensure restart save is exclusive to prevent save corruption

This commit is contained in:
zznty
2024-11-09 19:06:10 +07:00
parent 58340e0f5d
commit d15985e918
3 changed files with 8 additions and 3 deletions

View File

@@ -33,6 +33,11 @@
/// <summary> /// <summary>
/// The save operation timed out /// The save operation timed out
/// </summary> /// </summary>
TimedOut = -5 TimedOut = -5,
/// <summary>
/// Another save operation is in progress
/// </summary>
ConcurrentSaveInProgress = -6
} }
} }

View File

@@ -248,7 +248,7 @@ namespace Torch.Server
{ {
if (save) if (save)
{ {
var saveResult = Save().Result; var saveResult = Save(exclusive: true).Result;
if (saveResult is not (GameSaveResult.Success or GameSaveResult.TimedOut)) if (saveResult is not (GameSaveResult.Success or GameSaveResult.TimedOut))
{ {
Log.Error("Save failed due to {Reason}. Restart aborted!", saveResult); Log.Error("Save failed due to {Reason}. Restart aborted!", saveResult);

View File

@@ -330,7 +330,7 @@ namespace Torch
if (MyAsyncSaving.InProgress || _inProgressSaves > 0) if (MyAsyncSaving.InProgress || _inProgressSaves > 0)
{ {
Log.Error("Failed to save game, game is already saving"); Log.Error("Failed to save game, game is already saving");
return null; return Task.FromResult(GameSaveResult.ConcurrentSaveInProgress);
} }
} }