From: Tuukka Lehtonen Date: Mon, 26 Mar 2018 15:36:02 +0000 (+0300) Subject: Improved network-drive-resilience in index directory creation X-Git-Tag: v1.43.0~136^2~519 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=cc084b2c81c8b47adfd1d33b507164c6c42728fa;p=simantics%2Fplatform.git Improved network-drive-resilience in index directory creation In a product, the removed Files.exists(p) && !Files.isDirectory(p) code threw an exception because the examined path was not guaranteed to be in a coherent state at the time of examination but Files.createDirectories would still take care of throwing any exceptions if there were any problems in creating the directory. The worst thing was that this exception was hidden and not even logged. Luckily a problem case forced the find. refs #7845 Change-Id: Id44c5118ad97fbb83dcec87f77717185d3e402a1 --- diff --git a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java index 136a7bcf6..9c3f75bf2 100644 --- a/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java +++ b/bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java @@ -633,7 +633,7 @@ abstract public class IndexedRelationsSearcherBase { try { mon.subTask("Start index write"); - createDirectory(indexPath); + Files.createDirectories(indexPath); directory.set(FSDirectory.open(indexPath.toFile())); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_9, Queries.getAnalyzer()).setOpenMode(OpenMode.CREATE); @@ -992,12 +992,6 @@ abstract public class IndexedRelationsSearcherBase { return path; } - private static void createDirectory(Path path) throws IOException { - if (Files.exists(path) && !Files.isDirectory(path)) - throw new IOException("Could not create index directory " + path + ", a file by that name already exists"); - Files.createDirectories(path); - } - Path getIndexPath() { return indexPath; }