Skip to content

Commit

Permalink
Fixed a bug where backups would use the same icon
Browse files Browse the repository at this point in the history
  • Loading branch information
MehradN committed Mar 5, 2023
1 parent 18e23b5 commit 081530c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/main/java/ir/mehradn/rollback/util/backup/BackupManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public boolean createRollbackBackup(MinecraftServer server) {

while (array.size() >= RollbackConfig.getMaxBackupsPerWorld())
deleteBackup(worldName, 0);
deleteNonexistentIcons(worldName);

Rollback.LOGGER.debug("Saving the world...");
boolean f = server.saveAll(true, true, true);
Expand Down Expand Up @@ -205,8 +206,9 @@ public boolean deleteBackup(String worldName, int index) {

Rollback.LOGGER.debug("Deleting the files...");
try {
Files.deleteIfExists(this.rollbackDirectory.resolve(backup.iconPath));
Files.deleteIfExists(this.rollbackDirectory.resolve(backup.backupPath));
if (backup.iconPath != null)
Files.deleteIfExists(this.rollbackDirectory.resolve(backup.iconPath));
} catch (IOException e) {
showError("rollback.deleteBackup.failed", "Failed to delete the files!", e);
return false;
Expand Down Expand Up @@ -275,6 +277,18 @@ public void deleteAllBackupsFor(String worldName) {
saveMetadata();
}

private void deleteNonexistentIcons(String worldName) {
JsonArray array = getWorldObject(worldName).getAsJsonArray("backups");
for (JsonElement elm : array) {
JsonObject obj = elm.getAsJsonObject();
if (!obj.has("icon_file"))
continue;
String iconPath = obj.get("icon_file").getAsString();
if (!Files.isRegularFile(this.rollbackDirectory.resolve(iconPath)))
obj.remove("icon_file");
}
}

/*
public void cleanUp() {
List<String> worldNames;
Expand Down

0 comments on commit 081530c

Please sign in to comment.