avoid exposing game to partially written mod files during first download

This avoids mod loading failure messages caused by partially
copied mod files after initial download, the same way it is
already avoided while loading files from cache.
This commit is contained in:
Katharine Chui
2026-05-11 14:13:27 +02:00
parent 5fc8f580f4
commit 8b4fefd518
+11 -2
View File
@@ -583,13 +583,17 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
c = ::tolower(c); c = ::tolower(c);
} }
#endif #endif
auto name = std::filesystem::path(GetGamePath()) / "mods/multiplayer" / FName;
auto tmp_name = name;
tmp_name += ".tmp";
std::error_code ec; std::error_code ec;
fs::copy_file(PathToSaveTo, std::filesystem::path(GetGamePath()) / "mods/multiplayer" / FName, fs::copy_options::overwrite_existing, ec); fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing, ec);
if (ec) { if (ec) {
error(beammp_wide("Error in copy_file during download of ") + beammp_fs_string(PathToSaveTo) + beammp_wide(": ") + Utils::ToWString(ec.message())); error(beammp_wide("Error in copy_file during download of ") + beammp_fs_string(PathToSaveTo) + beammp_wide(": ") + Utils::ToWString(ec.message()));
break; break;
} }
fs::rename(tmp_name, name);
UpdateModUsage(FName); UpdateModUsage(FName);
} }
WaitForConfirm(); WaitForConfirm();
@@ -748,7 +752,12 @@ void SyncResources(SOCKET Sock) {
} }
#endif #endif
fs::copy_file(PathToSaveTo, GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(FName), fs::copy_options::overwrite_existing); auto name = GetGamePath() / beammp_wide("mods/multiplayer") / Utils::ToWString(FName);
auto tmp_name = name;
tmp_name += L".tmp";
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
fs::rename(tmp_name, name);
UpdateModUsage(FN->substr(pos)); UpdateModUsage(FN->substr(pos));
} }
WaitForConfirm(); WaitForConfirm();