Renamed isValid -> isValidBackup

This commit is contained in:
szymon 2020-08-11 09:51:34 +02:00
parent 786666f827
commit 7b6531185d
3 changed files with 9 additions and 12 deletions

View File

@ -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);
}

View File

@ -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<File> 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<File> it = Arrays.stream(root.listFiles())
.filter(BackupHelper::isFileOk)
.filter(Utilities::isValid)
.filter(Utilities::isValidBackup)
.sorted(Comparator.comparing(f -> Utilities.getFileCreationTime(f).get()))
.iterator();

View File

@ -36,8 +36,7 @@ public class RestoreHelper {
File root = Utilities.getBackupRootPath(Utilities.getLevelName(server));
Optional<File> 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());
}