Fix archive cleaner when no directory exists

This commit is contained in:
Laura Gorzitze
2023-09-05 10:15:45 +02:00
parent f8622ed755
commit 3a99fe7a82
2 changed files with 16 additions and 8 deletions

View File

@@ -42,15 +42,17 @@ public class PluginArchiveCleaner {
public void cleanup(Path archivePath) throws IOException {
try (Stream<Path> pathStream = Files.list(archivePath)) {
List<Path> pathList = pathStream
.filter(PluginArchiveCleaner::isAnInstalledPluginDirectory)
.sorted()
.collect(Collectors.toList());
if (Files.exists(archivePath)) {
try (Stream<Path> pathStream = Files.list(archivePath)) {
List<Path> pathList = pathStream
.filter(PluginArchiveCleaner::isAnInstalledPluginDirectory)
.sorted()
.collect(Collectors.toList());
for (int i = 0; i <= pathList.size() - MAX_ARCHIVE_COUNT; i++) {
LOG.debug("Delete old installation directory {}", pathList.get(i));
IOUtil.deleteSilently(pathList.get(i).toFile());
for (int i = 0; i <= pathList.size() - MAX_ARCHIVE_COUNT; i++) {
LOG.debug("Delete old installation directory {}", pathList.get(i));
IOUtil.deleteSilently(pathList.get(i).toFile());
}
}
}
}