Nice
This commit is contained in:
parent
fdc8d34f82
commit
64059984d3
@ -1,6 +1,5 @@
|
||||
package be.simplenotes.search
|
||||
|
||||
import be.simplenotes.search.utils.rmdir
|
||||
import be.simplenotes.types.PersistedNote
|
||||
import org.apache.lucene.analysis.standard.StandardAnalyzer
|
||||
import org.apache.lucene.document.Document
|
||||
@ -90,7 +89,11 @@ internal class NoteSearcherImpl(basePath: Path = Path.of("/tmp", "lucene")) : No
|
||||
emptyList()
|
||||
}
|
||||
|
||||
override fun dropIndex(userId: Int) = rmdir(File(baseFile, userId.toString()).toPath())
|
||||
override fun dropIndex(userId: Int) {
|
||||
File(baseFile, userId.toString()).deleteRecursively()
|
||||
}
|
||||
|
||||
override fun dropAll() = rmdir(baseFile.toPath())
|
||||
override fun dropAll() {
|
||||
baseFile.deleteRecursively()
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
package be.simplenotes.search.utils
|
||||
|
||||
import java.io.IOException
|
||||
import java.nio.file.FileVisitResult
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.SimpleFileVisitor
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
internal fun rmdir(path: Path) {
|
||||
try {
|
||||
Files.walkFileTree(
|
||||
path,
|
||||
object : SimpleFileVisitor<Path>() {
|
||||
override fun visitFile(file: Path, attrs: BasicFileAttributes?): FileVisitResult {
|
||||
Files.delete(file)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
|
||||
override fun postVisitDirectory(dir: Path, exc: IOException?): FileVisitResult {
|
||||
Files.delete(dir)
|
||||
return FileVisitResult.CONTINUE
|
||||
}
|
||||
}
|
||||
)
|
||||
} catch (e: IOException) {
|
||||
// This is fine
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user