From 3f8520ed95e600a713ed677cc3ae21780ea2a5e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Prante?= Date: Fri, 6 Oct 2023 16:24:51 +0200 Subject: [PATCH] fix journal purging --- .../server/application/journal/Journal.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/net-http-server-application-journal/src/main/java/org/xbib/net/http/server/application/journal/Journal.java b/net-http-server-application-journal/src/main/java/org/xbib/net/http/server/application/journal/Journal.java index 941fa6a..d69d8ae 100644 --- a/net-http-server-application-journal/src/main/java/org/xbib/net/http/server/application/journal/Journal.java +++ b/net-http-server-application-journal/src/main/java/org/xbib/net/http/server/application/journal/Journal.java @@ -109,17 +109,19 @@ public class Journal { writeLock.lock(); PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request"); try { - Files.walkFileTree(journalPath.resolve("success"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { - if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { - if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { - Files.delete(p); + if (Files.exists(journalPath.resolve("success"))) { + Files.walkFileTree(journalPath.resolve("success"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { + if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { + if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { + Files.delete(p); + } } + return FileVisitResult.CONTINUE; } - return FileVisitResult.CONTINUE; - } - }); + }); + } } finally { writeLock.unlock(); } @@ -130,17 +132,19 @@ public class Journal { writeLock.lock(); PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request"); try { - Files.walkFileTree(journalPath.resolve("fail"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { - @Override - public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { - if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { - if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { - Files.delete(p); + if (Files.exists(journalPath.resolve("fail"))) { + Files.walkFileTree(journalPath.resolve("fail"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { + @Override + public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { + if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { + if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { + Files.delete(p); + } } + return FileVisitResult.CONTINUE; } - return FileVisitResult.CONTINUE; - } - }); + }); + } } finally { writeLock.unlock(); }