]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/IndexedRelationsSearcherBase.java
Worked around Windows FS problems in IndexedRelationsSearcherBase
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / IndexedRelationsSearcherBase.java
index 92cbe56d12bacfa76d30696811d90a01cfe4f00f..387b2b509bc930ef15965726cc053e20c786a8ca 100644 (file)
@@ -14,6 +14,7 @@ package org.simantics.db.indexing;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -577,7 +578,7 @@ abstract public class IndexedRelationsSearcherBase {
         @Override
         public Thread newThread(Runnable r) {
             Thread t = new Thread(r, "Lucene Index Creator");
-            if (t.isDaemon())
+            if (!t.isDaemon())
                 t.setDaemon(true);
             if (t.getPriority() != Thread.NORM_PRIORITY)
                 t.setPriority(Thread.NORM_PRIORITY);
@@ -611,7 +612,7 @@ abstract public class IndexedRelationsSearcherBase {
 
         if (overwrite) {
             mon.subTask("Erasing previous index");
-            FileUtils.deleteAll(indexPath);
+            FileUtils.emptyDirectory(indexPath.toPath());
         }
 
         final AtomicReference<FSDirectory> directory = new AtomicReference<FSDirectory>();
@@ -619,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);
@@ -675,10 +676,10 @@ abstract public class IndexedRelationsSearcherBase {
                                 }
                             }
                         }
-
-                        s.release();
                     } catch (DatabaseException e) {
                         throw new IllegalStateException(e);
+                    } finally {
+                        s.release();
                     }
                 });
             }
@@ -708,7 +709,7 @@ abstract public class IndexedRelationsSearcherBase {
             try {
                 closeWriter(writer.getAndSet(null));
             } finally {
-                directory.getAndSet(null).close();
+                FileUtils.uncheckedClose(directory.getAndSet(null));
             }
         }
     }
@@ -980,16 +981,6 @@ abstract public class IndexedRelationsSearcherBase {
         return path;
     }
 
-    private static void createDirectory(File path) throws IOException {
-        if (path.exists() && !path.isDirectory())
-            throw new IOException("Could not create index directory " + path + ", a file by that name already exists");
-        path.mkdirs();
-        if (!path.exists())
-            throw new IOException("Could not create index directory " + path + " for an unknown reason");
-        if (!path.isDirectory())
-            throw new IOException("Could not create index directory " + path + ", a file by that name already exists");
-    }
-
     File getIndexPath() {
         return indexPath;
     }