Fix file list bug

pull/398/head
johnniang 2019-11-21 23:27:47 +08:00
parent b7cf5576af
commit 35ab8407d8
1 changed files with 15 additions and 12 deletions

View File

@ -39,6 +39,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Backup service implementation.
@ -179,18 +180,20 @@ public class BackupServiceImpl implements BackupService {
public List<BackupDTO> listHaloBackups() {
try {
// Build backup dto
return Files.list(Paths.get(haloProperties.getBackupDir()))
.filter(backupPath -> StringUtils.startsWithIgnoreCase(backupPath.getFileName().toString(), HaloConst.HALO_BACKUP_PREFIX))
.map(this::buildBackupDto)
.sorted((leftBackup, rightBackup) -> {
// Sort the result
if (leftBackup.getUpdateTime() < rightBackup.getUpdateTime()) {
return 1;
} else if (leftBackup.getUpdateTime() > rightBackup.getUpdateTime()) {
return -1;
}
return 0;
}).collect(Collectors.toList());
try (Stream<Path> subPathStream = Files.list(Paths.get(haloProperties.getBackupDir()))) {
return subPathStream
.filter(backupPath -> StringUtils.startsWithIgnoreCase(backupPath.getFileName().toString(), HaloConst.HALO_BACKUP_PREFIX))
.map(this::buildBackupDto)
.sorted((leftBackup, rightBackup) -> {
// Sort the result
if (leftBackup.getUpdateTime() < rightBackup.getUpdateTime()) {
return 1;
} else if (leftBackup.getUpdateTime() > rightBackup.getUpdateTime()) {
return -1;
}
return 0;
}).collect(Collectors.toList());
}
} catch (IOException e) {
throw new ServiceException("Failed to fetch backups", e);
}