summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorKeuin <[email protected]>2021-10-10 21:46:23 +0800
committerKeuin <[email protected]>2021-10-10 21:46:23 +0800
commit47c3cbd0a08869c51dfda75868a80471d6e3b675 (patch)
tree16a8863df93eb344556a0e2017e087d0de473db6 /src/main
parent6d094a5c67c9b3f4da5c66b92db97e1fb5e08118 (diff)
Bugfix: `/kb` will fail if the backup directory does not exist.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/keuin/kbackupfabric/ui/BackupManager.java16
1 files changed, 15 insertions, 1 deletions
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<BackupInfo> 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<BackupInfo>() {
- private final Iterator<File> fileIterator = Arrays.stream(backupStorageDirectory.listFiles()).filter(file -> {
+ private final Iterator<File> fileIterator = Arrays.stream(backupFiles).filter(file -> {
String name = file.getName().toLowerCase();
return name.endsWith(".zip") || name.endsWith(".kbi");
}).iterator();