From 2165057a62b619a4ad224ec13852d2a6b72c45b4 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Fri, 12 Aug 2022 21:46:12 +0100 Subject: [PATCH] delete any stale blockfiles --- .../java/com/muwire/core/search/SearchIndexImpl.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/com/muwire/core/search/SearchIndexImpl.java b/core/src/main/java/com/muwire/core/search/SearchIndexImpl.java index 6f8cbaad..69e28be5 100644 --- a/core/src/main/java/com/muwire/core/search/SearchIndexImpl.java +++ b/core/src/main/java/com/muwire/core/search/SearchIndexImpl.java @@ -9,6 +9,11 @@ import java.io.*; import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.FileVisitor; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.BasicFileAttributes; import java.util.*; public class SearchIndexImpl { @@ -18,6 +23,12 @@ public class SearchIndexImpl { private final BlockFile blockFile; SearchIndexImpl(File dir, String name) throws IOException { + + // delete any stale blockfiles + Files.walk(dir.toPath()). + filter(path -> {return path.getFileName().toString().startsWith(name);}). + forEach(path -> {path.toFile().delete();}); + blockFile = new BlockFile(dir, name, true); keywords = blockFile.makeIndex("keywords", new StringSerializer(), new HashArraySerializer()); hashes = blockFile.makeIndex("hashes", new HashSerializer(), new StringArraySerializer2());