Fix replay recording temporary paths not supporting subdirectories (#19887)

This commit is contained in:
Leon Friedrich
2023-09-16 23:46:12 +12:00
committed by GitHub
parent ac0b8fe621
commit 7d9693d976
3 changed files with 64 additions and 6 deletions

View File

@@ -0,0 +1,56 @@
using Content.Server.GameTicking;
using Content.Shared.CCVar;
using Robust.Shared;
using Robust.Shared.Replays;
namespace Content.IntegrationTests.Tests.Replays;
[TestFixture]
public sealed class ReplayTests
{
/// <summary>
/// Simple test that just makes sure that automatic replay recording on round restarts works without any issues.
/// </summary>
[Test]
public async Task AutoRecordReplayTest()
{
var settings = new PoolSettings {DummyTicker = false};
await using var pair = await PoolManager.GetServerClient(settings);
var server = pair.Server;
Assert.That(server.CfgMan.GetCVar(CVars.ReplayServerRecordingEnabled), Is.False);
var recordMan = server.ResolveDependency<IReplayRecordingManager>();
Assert.That(recordMan.IsRecording, Is.False);
// Setup cvars.
var autoRec = server.CfgMan.GetCVar(CCVars.ReplayAutoRecord);
var autoRecName = server.CfgMan.GetCVar(CCVars.ReplayAutoRecordName);
var tempDir = server.CfgMan.GetCVar(CCVars.ReplayAutoRecordTempDir);
server.CfgMan.SetCVar(CVars.ReplayServerRecordingEnabled, true);
server.CfgMan.SetCVar(CCVars.ReplayAutoRecord, true);
server.CfgMan.SetCVar(CCVars.ReplayAutoRecordTempDir, "/a/b/");
server.CfgMan.SetCVar(CCVars.ReplayAutoRecordName, $"c/d/{autoRecName}");
// Restart the round a few times
var ticker = server.System<GameTicker>();
await server.WaitPost(() => ticker.RestartRound());
await pair.RunTicksSync(25);
Assert.That(recordMan.IsRecording, Is.True);
await server.WaitPost(() => ticker.RestartRound());
await pair.RunTicksSync(25);
Assert.That(recordMan.IsRecording, Is.True);
// Reset cvars
server.CfgMan.SetCVar(CVars.ReplayServerRecordingEnabled, false);
server.CfgMan.SetCVar(CCVars.ReplayAutoRecord, autoRec);
server.CfgMan.SetCVar(CCVars.ReplayAutoRecordTempDir, tempDir);
server.CfgMan.SetCVar(CCVars.ReplayAutoRecordName, autoRecName);
// Restart the round again to disable the current recording.
await server.WaitPost(() => ticker.RestartRound());
await pair.RunTicksSync(25);
Assert.That(recordMan.IsRecording, Is.False);
await pair.CleanReturnAsync();
}
}

View File

@@ -72,13 +72,14 @@ public sealed partial class GameTicker
if (data.State is not ReplayRecordState state)
return;
if (state.MoveToPath != null)
{
_sawmillReplays.Info($"Moving replay into final position: {state.MoveToPath}");
if (state.MoveToPath == null)
return;
_taskManager.BlockWaitOnTask(_replays.WaitWriteTasks());
data.Directory.Rename(data.Path, state.MoveToPath.Value);
}
_sawmillReplays.Info($"Moving replay into final position: {state.MoveToPath}");
_taskManager.BlockWaitOnTask(_replays.WaitWriteTasks());
DebugTools.Assert(!_replays.IsWriting());
data.Directory.CreateDir(state.MoveToPath.Value.Directory);
data.Directory.Rename(data.Path, state.MoveToPath.Value);
}
private ResPath GetAutoReplayPath()

View File

@@ -1776,6 +1776,7 @@ namespace Content.Shared.CCVar
/// <summary>
/// Path that, if provided, automatic replays are initially recorded in.
/// When the recording is done, the file is moved into its final destination.
/// Unless this path is rooted, it will be relative to <see cref="CVars.ReplayDirectory"/>.
/// </summary>
public static readonly CVarDef<string> ReplayAutoRecordTempDir =
CVarDef.Create("replay.auto_record_temp_dir", "", CVar.SERVERONLY);