From 64059984d323e0a1d7a6ec8955ec9059bd986ee5 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Mon, 26 Oct 2020 22:24:56 +0100 Subject: [PATCH] Nice --- .../be/simplenotes/search/NoteSearcherImpl.kt | 9 ++++-- .../be/simplenotes/search/utils/PathUtils.kt | 29 ------------------- 2 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 simplenotes-search/src/main/kotlin/be/simplenotes/search/utils/PathUtils.kt diff --git a/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt b/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt index 5fcce1c..a5f5b44 100644 --- a/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt +++ b/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt @@ -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() + } } diff --git a/simplenotes-search/src/main/kotlin/be/simplenotes/search/utils/PathUtils.kt b/simplenotes-search/src/main/kotlin/be/simplenotes/search/utils/PathUtils.kt deleted file mode 100644 index fd5966e..0000000 --- a/simplenotes-search/src/main/kotlin/be/simplenotes/search/utils/PathUtils.kt +++ /dev/null @@ -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() { - 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 - } -}