fix journal purging

This commit is contained in:
Jörg Prante 2023-10-06 16:24:51 +02:00
parent acdbd0c028
commit 3f8520ed95

View file

@ -109,17 +109,19 @@ public class Journal {
writeLock.lock(); writeLock.lock();
PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request"); PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request");
try { try {
Files.walkFileTree(journalPath.resolve("success"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { if (Files.exists(journalPath.resolve("success"))) {
@Override Files.walkFileTree(journalPath.resolve("success"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { @Override
if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException {
if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) {
Files.delete(p); if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) {
Files.delete(p);
}
} }
return FileVisitResult.CONTINUE;
} }
return FileVisitResult.CONTINUE; });
} }
});
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
} }
@ -130,17 +132,19 @@ public class Journal {
writeLock.lock(); writeLock.lock();
PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request"); PathMatcher pathMatcher = journalPath.getFileSystem().getPathMatcher("glob:*.request");
try { try {
Files.walkFileTree(journalPath.resolve("fail"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() { if (Files.exists(journalPath.resolve("fail"))) {
@Override Files.walkFileTree(journalPath.resolve("fail"), EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor<>() {
public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException { @Override
if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) { public FileVisitResult visitFile(Path p, BasicFileAttributes a) throws IOException {
if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) { if ((Files.isRegularFile(p) && pathMatcher.matches(p.getFileName()))) {
Files.delete(p); if (Files.getLastModifiedTime(p).toInstant().isBefore(instant)) {
Files.delete(p);
}
} }
return FileVisitResult.CONTINUE;
} }
return FileVisitResult.CONTINUE; });
} }
});
} finally { } finally {
writeLock.unlock(); writeLock.unlock();
} }