|
Player12
An open source football management simulator
|
#include <save_manager.h>
Public Types | |
| enum class | FaultPoint : std::uint8_t { MidFlush , TempOpened , SnapshotWritten , Rotated } |
| using | FaultHook = std::function< void(FaultPoint, sqlite3 *temp_db)> |
Static Public Member Functions | |
| static void | setFaultHook (FaultHook hook) |
| static void | fault (FaultPoint point, sqlite3 *temp_db=nullptr) |
| static SaveInspection | inspect (const std::filesystem::path &file, SaveCheck check=SaveCheck::Full) |
| static std::shared_ptr< DatabaseConnection > | openWorkingCopy (const std::filesystem::path &file) |
| static std::shared_ptr< DatabaseConnection > | createWorkingCopy () |
| static void | stampMetadata (const DatabaseConnection &working, std::uint64_t world_seed, const GameDateValue &game_date, std::int64_t playtime_seconds) |
| static SaveTimings | persist (const DatabaseConnection &working, const std::filesystem::path &file, int backups) |
| static void | preserveBeforeMigration (const std::filesystem::path &file, int schema_version) |
| static int | countBackups (const std::filesystem::path &file) |
| static std::vector< SaveBackup > | listBackups (const std::filesystem::path &file) |
| static const SaveBackup * | newestUsable (const std::vector< SaveBackup > &backups) |
| static void | restoreBackup (const std::filesystem::path &file, const std::filesystem::path &backup) |
| static void | deleteSave (const std::filesystem::path &file) |
| static bool | isAutosaveDue (AutosaveFrequency frequency, const GameDateValue &last_autosave, int last_autosave_season, const GameDateValue &today, int season, bool managed_match_yesterday) |
| static std::filesystem::path | backupPath (const std::filesystem::path &file, int index) |
| static std::filesystem::path | tempPath (const std::filesystem::path &file) |
Crash-safe persistence of career saves.
A career is played on an in-memory working database; the slot file is only replaced by a complete, verified snapshot (online backup to <slot>.tmp, quick_check, fsync, rotate backups, atomic rename, fsync of the directory). An interrupted save therefore never damages the previous one. See src/database/migrations/README.md, "Save protocol".
| using SaveManager::FaultHook = std::function<void(FaultPoint, sqlite3* temp_db)> |
|
strong |
Places where tests inject faults (kill, disk full, I/O errors).
| Enumerator | |
|---|---|
| MidFlush | Inside Game::saveGame's transaction. |
| TempOpened | Temporary file opened, before the backup. |
| SnapshotWritten | Backup done, before verification. |
| Rotated | Backups rotated, before the rename. |
|
static |
|
static |
Number of rotation backups of a slot (no file is opened).
|
static |
A new, empty in-memory working database.
|
static |
Removes a save with its sidecars, temporary file and backups.
|
static |
|
static |
Read-only inspection; never modifies the file.
|
static |
Whether an autosave is due today.
|
static |
Rotation and pre-migration backups of a slot, newest first.
|
static |
The newest backup of backups (as listed by listBackups) that loads, or nullptr: what a recovery dialog offers first.
|
static |
Copies a save into a new in-memory working database (online backup; content of a leftover -wal file from a crash is included).
| SaveFailure | when the file cannot be read. |
|
static |
Atomically replaces file with a snapshot of working, keeping backups previous versions. On failure the previous file and its backups are unchanged.
| SaveFailure | (DiskFull, PermissionDenied, Io). |
|
static |
Keeps a copy of a save before its schema is upgraded (once).
|
static |
Replaces file with backup (verified first). The replaced file is kept as <file>.corrupt-<utc> or <file>.replaced-<utc>, never deleted.
| SaveFailure. |
|
static |
Test hook, called at every FaultPoint (nullptr to disable).
|
static |
Writes the provenance of this save into save_meta of working, including the game, engine, RNG and simulation versions of this build.
|
static |