Commit
7af1f86d31d9007157477d1f4ad934b825761f4a
by 127477265+cyrne1-7208Fix FlatFile database truncation on read failure
In FlatFileDatabaseManager, methods that read the database before writing
(newUser, purgePowerlessUsers, purgeOldUsers, removeUser, saveUserUUID,
saveUserUUIDs, and checkFileHealthAndStructure) previously continued
to write or rewrite the database file even when reading encountered an
IOException. This caused partial or empty contents to overwrite mcmmo.users,
resulting in data loss / truncation.
This change:
- Guards newUser() by returning an unloaded PlayerProfile on IOException,
preventing the subsequent FileWriter block from overwriting the database.
- Guards purgePowerlessUsers() by returning 0 on IOException without writing.
- Guards rewriteUsersFile() to return false on IOException without writing,
and updates its callers (purgeOldUsers, removeUser, saveUserUUIDs) to abort
early on read failure.
- Guards saveUserUUID() to return false on exception without writing.
- Guards checkFileHealthAndStructure() to return null on validation IOException,
preventing the subsequent update block from overwriting the database.
- Adds comprehensive unit tests verifying that a mid-stream read failure
leaves the database file byte-for-byte identical across all operations.
Signed-off-by: Cyrne1_7208 <127477265+cyrne1-7208@users.noreply.github.com>
(commit: 7af1f86)