MetadataWriter: add fallback to level.dat_old

Looking at inotify dumps, it appears like because of bad implementation
choices, Minecraft's level.dat may not exist for a brief moment between
moving the old file to level.dat_old and moving a new version into place.

Add a fallback to level.dat_old, so generation will not fail if were
unlucky enough to hit this moment.
This commit is contained in:
Matthias Schiffer 2025-02-13 20:10:50 +01:00
parent 971afea727
commit 37126f69fc
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
2 changed files with 14 additions and 1 deletions

View file

@ -124,7 +124,14 @@ impl<'a> MetadataWriter<'a> {
/// Reads and deserializes the `level.dat` of the Minecraft save data
fn read_level_dat(&self) -> Result<de::LevelDat> {
crate::nbt::data::from_file(&self.config.level_dat_path).context("Failed to read level.dat")
let res = crate::nbt::data::from_file(&self.config.level_dat_path);
if res.is_err() {
if let Ok(level_dat_old) = crate::nbt::data::from_file(&self.config.level_dat_old_path)
{
return Ok(level_dat_old);
}
}
res.context("Failed to read level.dat")
}
/// Generates [Spawn] data from a [de::LevelDat]