From 7b6531185dfabbbd95e086e2071569c7b5bb93f4 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 11 Aug 2020 09:51:34 +0200 Subject: [PATCH] Renamed isValid -> isValidBackup --- .../net/szum123321/textile_backup/core/Utilities.java | 6 ++++-- .../textile_backup/core/create/BackupHelper.java | 9 +++------ .../textile_backup/core/restore/RestoreHelper.java | 6 ++---- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/szum123321/textile_backup/core/Utilities.java b/src/main/java/net/szum123321/textile_backup/core/Utilities.java index ffd38df..dec4b1c 100644 --- a/src/main/java/net/szum123321/textile_backup/core/Utilities.java +++ b/src/main/java/net/szum123321/textile_backup/core/Utilities.java @@ -151,10 +151,12 @@ public class Utilities { return path; } - public static boolean isValid(File f) { - return getFileExtension(f).isPresent() && getFileCreationTime(f).isPresent(); + public static boolean isValidBackup(File f) { + return getFileExtension(f).isPresent() && getFileCreationTime(f).isPresent() && isFileOk(f); } + public static boolean isFileOk(File f) {return f.exists() && f.isFile(); } + public static DateTimeFormatter getDateTimeFormatter() { return DateTimeFormatter.ofPattern(Statics.CONFIG.dateTimeFormat); } diff --git a/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java b/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java index 3577796..1d27471 100644 --- a/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java +++ b/src/main/java/net/szum123321/textile_backup/core/create/BackupHelper.java @@ -67,8 +67,7 @@ public class BackupHelper { final LocalDateTime now = LocalDateTime.now(); Arrays.stream(root.listFiles()) - .filter(BackupHelper::isFileOk) - .filter(Utilities::isValid)// We check if we can get file's creation date so that the next line won't throw an exception + .filter(Utilities::isValidBackup)// We check if we can get file's creation date so that the next line won't throw an exception .filter(f -> now.toEpochSecond(ZoneOffset.UTC) - Utilities.getFileCreationTime(f).get().toEpochSecond(ZoneOffset.UTC) > Statics.CONFIG.maxAge) .forEach(f -> { if(deleteFile(f, ctx)) @@ -80,8 +79,7 @@ public class BackupHelper { int i = root.listFiles().length; Iterator it = Arrays.stream(root.listFiles()) - .filter(BackupHelper::isFileOk) - .filter(Utilities::isValid) + .filter(Utilities::isValidBackup) .sorted(Comparator.comparing(f -> Utilities.getFileCreationTime(f).get())) .iterator(); @@ -95,8 +93,7 @@ public class BackupHelper { if (Statics.CONFIG.maxSize > 0 && FileUtils.sizeOfDirectory(root) / 1024 > Statics.CONFIG.maxSize) { Iterator it = Arrays.stream(root.listFiles()) - .filter(BackupHelper::isFileOk) - .filter(Utilities::isValid) + .filter(Utilities::isValidBackup) .sorted(Comparator.comparing(f -> Utilities.getFileCreationTime(f).get())) .iterator(); diff --git a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java index cfc3821..9fada41 100644 --- a/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java +++ b/src/main/java/net/szum123321/textile_backup/core/restore/RestoreHelper.java @@ -36,8 +36,7 @@ public class RestoreHelper { File root = Utilities.getBackupRootPath(Utilities.getLevelName(server)); Optional optionalFile = Arrays.stream(root.listFiles()) - .filter(File::isFile) - .filter(Utilities::isValid) + .filter(Utilities::isValidBackup) .filter(file -> Utilities.getFileCreationTime(file).get().equals(backupTime)) .findFirst(); @@ -62,8 +61,7 @@ public class RestoreHelper { File root = Utilities.getBackupRootPath(Utilities.getLevelName(server)); return Arrays.stream(root.listFiles()) - .filter(File::isFile) - .filter(Utilities::isValid) + .filter(Utilities::isValidBackup) .map(RestoreableFile::new) .collect(Collectors.toList()); }