From 7401e36919727c20647085f2ff8277eaad568c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Richez?= Date: Mon, 7 Jun 2021 12:42:31 +0200 Subject: [PATCH] avoid using scala.reflect and use a safer way to delete rocksdb data --- src/main/scala/io/iohk/ethereum/Mantis.scala | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/scala/io/iohk/ethereum/Mantis.scala b/src/main/scala/io/iohk/ethereum/Mantis.scala index 6eb14bbce0..ca2bbd4f3d 100644 --- a/src/main/scala/io/iohk/ethereum/Mantis.scala +++ b/src/main/scala/io/iohk/ethereum/Mantis.scala @@ -3,8 +3,8 @@ package io.iohk.ethereum import io.iohk.ethereum.nodebuilder.{StdNode, TestNode} import io.iohk.ethereum.utils.{Config, Logger} +import java.nio.file.{Files, Paths} import java.util.logging.LogManager -import scala.reflect.io.Directory object Mantis extends Logger { def main(args: Array[String]): Unit = { @@ -13,8 +13,7 @@ object Mantis extends Logger { val node = if (Config.testmode) { log.info("Starting Mantis in test mode") - log.info("Deleting previous database {}", Config.Db.RocksDb.path) - Directory(Config.Db.RocksDb.path).deleteRecursively() + deleteRocksDBFiles() new TestNode } else new StdNode @@ -23,4 +22,12 @@ object Mantis extends Logger { node.start() } + + private def deleteRocksDBFiles(): Unit = { + log.info("Deleting previous database {}", Config.Db.RocksDb.path) + Files.list(Paths.get(Config.Db.RocksDb.path)) + .map(_.toFile) + .filter(_.isFile) + .forEach(f => f.delete()) + } }