From 47c3cbd0a08869c51dfda75868a80471d6e3b675 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 10 Oct 2021 21:46:23 +0800 Subject: Bugfix: `/kb` will fail if the backup directory does not exist. --- .../java/com/keuin/kbackupfabric/ui/BackupManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java b/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java index abd7d5b..d4081c6 100644 --- a/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java +++ b/src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java @@ -32,8 +32,22 @@ public class BackupManager { @NotNull @Override public Iterator iterator() { + if (backupStorageDirectory.exists()) { + if (!backupStorageDirectory.isDirectory()) { + throw new RuntimeException("Backup directory is not a directory."); + } + } else { + if (!backupStorageDirectory.mkdirs()) { + throw new RuntimeException("Backup directory does not exist and cannot be created."); + } + } + File[] backupFiles = backupStorageDirectory.listFiles(); + if (backupFiles == null) { + throw new RuntimeException("Cannot list files in backup directory."); + } + return new Iterator() { - private final Iterator fileIterator = Arrays.stream(backupStorageDirectory.listFiles()).filter(file -> { + private final Iterator fileIterator = Arrays.stream(backupFiles).filter(file -> { String name = file.getName().toLowerCase(); return name.endsWith(".zip") || name.endsWith(".kbi"); }).iterator(); -- cgit v1.2.3