delete any stale blockfiles

dbus-notify
Zlatin Balevsky 2022-08-12 21:46:12 +01:00
parent b93d026494
commit 2165057a62
No known key found for this signature in database
GPG Key ID: A72832072D525E41
1 changed files with 11 additions and 0 deletions

View File

@ -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());