Skip to content

Commit a4789e9

Browse files
committed
Remove empty replay recordings
1 parent 37e4166 commit a4789e9

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

libs/s25main/Replay.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ bool Replay::StopRecording()
7272
isRecording_ = false;
7373
file_.Close();
7474

75+
// Remove empty replay recordings. They are mostly produced when a game is aborted
76+
// during startup, for example after an early script error.
77+
if(lastGF_ == 0)
78+
{
79+
boost::system::error_code ec;
80+
boost::filesystem::remove(filepath_, ec);
81+
return !ec;
82+
}
83+
7584
BinaryFile file;
7685
if(!file.Open(filepath_, OpenFileMode::Read))
7786
return false;

tests/s25Main/integration/testSerialization.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,26 @@ struct ReplayMapFixture
398398
}
399399
};
400400

401+
BOOST_FIXTURE_TEST_CASE(EmptyReplayRecordingIsRemoved, ReplayMapFixture)
402+
{
403+
Replay replay;
404+
for(const BasePlayerInfo& player : players)
405+
replay.AddPlayer(player);
406+
replay.ggs.speed = GameSpeed::VeryFast;
407+
408+
TmpFile tmpFile(".rpl");
409+
BOOST_TEST_REQUIRE(tmpFile.isValid());
410+
tmpFile.close();
411+
bfs::remove(tmpFile.filePath);
412+
413+
BOOST_TEST_REQUIRE(replay.StartRecording(tmpFile.filePath, map, 42));
414+
BOOST_TEST_REQUIRE(replay.IsRecording());
415+
BOOST_TEST(replay.GetLastGF() == 0u);
416+
417+
BOOST_TEST_REQUIRE(replay.StopRecording());
418+
BOOST_TEST_REQUIRE(!replay.IsRecording());
419+
BOOST_TEST(!bfs::exists(tmpFile.filePath));
420+
}
401421
BOOST_FIXTURE_TEST_CASE(ReplayWithMap, ReplayMapFixture)
402422
{
403423
Replay replay;

0 commit comments

Comments
 (0)