From 515862acbdae109facc26e6c1296c15fb87b8eb1 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Fri, 30 Dec 2022 23:15:36 +0100 Subject: [PATCH] Fixing backup persist --- .../java/fr/pandacube/lib/core/backup/Persist.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/Persist.java b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/Persist.java index 5e6d33b..e3b2883 100644 --- a/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/Persist.java +++ b/pandalib-core/src/main/java/fr/pandacube/lib/core/backup/Persist.java @@ -6,7 +6,6 @@ import fr.pandacube.lib.core.json.Json; import fr.pandacube.lib.util.Log; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; @@ -24,7 +23,7 @@ public class Persist { public Persist(BackupManager bm) { backupManager = bm; - file = new File(bm.getBackupDirectory(), "source-dirty-since.yml"); + file = new File(bm.getBackupDirectory(), "source-dirty-since.json"); load(); } @@ -34,11 +33,11 @@ public class Persist { protected void load() { boolean loaded = false; - try { - dirtySince = Json.gson.fromJson(new FileReader(file), new TypeToken>(){}.getType()); + try (FileReader reader = new FileReader(file)) { + dirtySince = Json.gson.fromJson(reader, new TypeToken>(){}.getType()); loaded = true; } - catch (final FileNotFoundException ignored) { } + catch (final IOException ignored) { } catch (final JsonParseException e) { Log.severe("cannot load " + file, e); } @@ -53,10 +52,9 @@ public class Persist { } public void save() { - try { - Json.gsonPrettyPrinting.toJson(dirtySince, new FileWriter(file, false)); + try (FileWriter writer = new FileWriter(file, false)) { + Json.gsonPrettyPrinting.toJson(dirtySince, writer); } - catch (final FileNotFoundException ignored) { } catch (final JsonParseException | IOException e) { Log.severe("could not save " + file, e); }