X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.acorn%2Fsrc%2Forg%2Fsimantics%2Facorn%2Finternal%2FAcornDatabase.java;h=8109df6cd25fd8a4ca2f4a9cdacd405ff6b60b7c;hp=a423fbdbe23b815871688fb17cb2c6fb165550f7;hb=e5c006a3e29dcb1f29ae5bcc21ac28573bd37648;hpb=bf495713dbc9dec325f3929889466fa6cd58b541 diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java index a423fbdbe..8109df6cd 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java @@ -13,6 +13,7 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.EnumSet; import java.util.Properties; +import java.util.stream.Stream; import org.simantics.acorn.GraphClientImpl2; import org.simantics.db.Database; @@ -23,6 +24,8 @@ import org.simantics.db.server.ProCoreException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fi.vtt.simantics.procore.internal.StaticSessionProperties; + /** * @author Tuukka Lehtonen */ @@ -112,6 +115,15 @@ public class AcornDatabase implements Database { @Override public void deleteFiles() throws ProCoreException { deleteTree(folder); + File vgPath = StaticSessionProperties.virtualGraphStoragePath; + if (vgPath != null) { + try (Stream vgs = Files.list(vgPath.toPath())) { + for (Path p : vgs.toArray(Path[]::new)) + deleteTree(p); + } catch (IOException e) { + throw new ProCoreException(e); + } + } } @Override @@ -147,6 +159,8 @@ public class AcornDatabase implements Database { raLockFile = null; Files.deleteIfExists(lockFile); isRunning = false; + safeLoggingClose(currentClient, currentClient.getDbFolder()); + currentClient = null; } catch (IOException e) { LOGGER.error("Failed to start database at " + folder.toAbsolutePath(), e); } @@ -224,39 +238,37 @@ public class AcornDatabase implements Database { throw new UnsupportedOperationException(); } - private static void deleteTree(Path path) throws ProCoreException { - if (!Files.exists(path)) - return; - - class Visitor extends SimpleFileVisitor { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + static class Visitor extends SimpleFileVisitor { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + try { + Files.delete(file); + } catch (IOException ioe) { + LOGGER.error("Failed to delete file {}", file, ioe); + throw ioe; + } + return FileVisitResult.CONTINUE; + } + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { + if (e == null) { try { - Files.delete(file); + Files.delete(dir); } catch (IOException ioe) { - ioe.printStackTrace(); + LOGGER.error("Failed to delete directory {}", dir, ioe); throw ioe; } return FileVisitResult.CONTINUE; } - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { - if (e == null) { - try { - Files.delete(dir); - } catch (IOException ioe) { - ioe.printStackTrace(); - throw ioe; - } - return FileVisitResult.CONTINUE; - } - throw e; - } + throw e; } + } + + private static void deleteTree(Path path) throws ProCoreException { + if (!Files.exists(path)) + return; try { - Visitor v = new Visitor(); - EnumSet opts = EnumSet.noneOf(FileVisitOption.class); - Files.walkFileTree(path, opts, Integer.MAX_VALUE, v); + Files.walkFileTree(path, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new Visitor()); } catch (IOException e) { throw new ProCoreException("Could not delete " + path, e); } @@ -272,7 +284,17 @@ public class AcornDatabase implements Database { return; try (AutoCloseable c = closeable) { } catch (Exception e) { - LOGGER.error("Failed to close " + closeable.getClass() + " of " + file.toAbsolutePath()); + LOGGER.error("Failed to close " + closeable.getClass() + " of " + file.toAbsolutePath(), e); + } + } + + private static void safeLoggingClose(Database.Session session, Path file) { + if (session == null) + return; + try { + session.close(); + } catch (Exception e) { + LOGGER.error("Failed to close " + session.getClass() + " of " + file.toAbsolutePath(), e); } }