From: Tuukka Lehtonen Date: Mon, 26 Mar 2018 11:52:39 +0000 (+0300) Subject: Improved network-drive-resilience in index directory creation X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=e89d0e20604e03d5eb44aa8d21fc322f02f5b480 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: Ic3ae84afeb798772996057eee33f7467c448f3e7 --- 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 cf22a0dbf..056a05e8a 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 @@ -15,7 +15,6 @@ package org.simantics.db.indexing; import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -621,7 +620,7 @@ abstract public class IndexedRelationsSearcherBase { try { mon.subTask("Start index write"); - createDirectory(indexPath); + Files.createDirectories(indexPath.toPath()); directory.set(FSDirectory.open(indexPath)); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_4_9, Queries.getAnalyzer()).setOpenMode(OpenMode.CREATE); @@ -982,13 +981,6 @@ abstract public class IndexedRelationsSearcherBase { return path; } - private static void createDirectory(File path) throws IOException { - Path p = path.toPath(); - if (Files.exists(p) && !Files.isDirectory(p)) - throw new IOException("Could not create index directory " + path + ", a file by that name already exists"); - Files.createDirectories(p); - } - File getIndexPath() { return indexPath; }