18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-20 12:44:59 +01:00

fix(physicslog): what no file name may have on Windows is replaced in the name of a log, on every system

A spawned vehicle is named <spawn>:<number>, and its log went to physicslog/<spawn>:<number>.dat. On
NTFS that isn't even an error: it is the stream <number>.dat of the file <spawn>, which nothing lists,
so the log was written and no one could find it. On Linux the file was there, under a name Windows
can't open.

The name of the file of a log has < > : " / \ | ? * and the control characters replaced by _, on every
system, so the logs are named alike everywhere (spawn_ezt:12 is spawn_ezt_12.dat), and a _ before a
name Windows keeps for a device (con, nul, com1..., with an extension too). The bytes of 1250 stay.
The black box tells the log it begins by the same name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maj00r
2026-11-16 13:00:16 +01:00
parent 5498995672
commit 0a1c4fd425
5 changed files with 63 additions and 12 deletions

View File

@@ -183,6 +183,29 @@ TEST_CASE("physicslog: a vehicle named in the code page of its scenery has its l
CHECK(log_folder::read_file(logs.file(name)) == std::string{header} + "0.0500 0.0000\r\n");
}
TEST_CASE("physicslog: what no file name may have on Windows is replaced in the name of the file, on every system") {
log_folder folder{"filename"};
physicslog_writer logs{folder.path(), std::chrono::hours{1}};
// a spawned vehicle's name has a ':', which on NTFS would write into a stream of the file "spawn_ezt"
CHECK(logs.file("spawn_ezt:12").filename() == "spawn_ezt_12.dat");
CHECK(logs.file("a<b>c\"d/e\\f|g?h*i\tj").filename() == "a_b_c_d_e_f_g_h_i_j.dat");
CHECK(logs.file("EN57-1001 'a'.2").filename() == "EN57-1001 'a'.2.dat");
// the devices of Windows, with an extension too, aren't files
CHECK(logs.file("nul").filename() == "_nul.dat");
CHECK(logs.file("Com1.2").filename() == "_Com1.2.dat");
CHECK(logs.file("con ").filename() == "_con .dat");
CHECK(logs.file("console").filename() == "console.dat");
CHECK(logs.file("com0").filename() == "com0.dat");
CHECK(logs.shown("spawn_ezt:12") == folder.path().generic_string() + "/spawn_ezt_12.dat");
logs.begin("spawn_ezt:12", header);
logs.append("spawn_ezt:12", "0.0500 0.0000\r\n");
logs.flush();
CHECK(folder.read("spawn_ezt_12") == std::string{header} + "0.0500 0.0000\r\n");
CHECK(false == std::filesystem::exists(folder.path() / "spawn_ezt"));
}
TEST_CASE("physicslog: stopping twice, from two threads at once, writes once and ends") {
log_folder folder{"stoptwice"};
physicslog_writer logs{folder.path(), std::chrono::milliseconds{20}};