From 3e64b336a8edcec559d8d3ed20e4d6541fadadfa Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Wed, 27 Jul 2016 06:11:50 +0200 Subject: [PATCH] Only create a database backup if there isn't one already. This prevents overwriting a perfectly fine backup with a more or less broken one in case a database update fails. --- src/main/java/de/fabianonline/telegram_backup/Database.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/fabianonline/telegram_backup/Database.java b/src/main/java/de/fabianonline/telegram_backup/Database.java index 58fa2bd..cd80448 100644 --- a/src/main/java/de/fabianonline/telegram_backup/Database.java +++ b/src/main/java/de/fabianonline/telegram_backup/Database.java @@ -41,6 +41,7 @@ import java.util.HashMap; import java.util.Date; import java.nio.file.Files; import java.nio.file.StandardCopyOption; +import java.nio.file.FileAlreadyExistsException; import java.text.SimpleDateFormat; import de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager; @@ -97,8 +98,9 @@ public class Database { logger.debug("Copying {} to {}", src, dst); Files.copy( new File(src).toPath(), - new File(dst).toPath(), - StandardCopyOption.REPLACE_EXISTING); + new File(dst).toPath()); + } catch (FileAlreadyExistsException e) { + logger.warn("Backup already exists:", e); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Could not create backup.");