]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.indexing/src/org/simantics/db/indexing/DatabaseIndexing.java
Worked around Windows FS problems in IndexedRelationsSearcherBase
[simantics/platform.git] / bundles / org.simantics.db.indexing / src / org / simantics / db / indexing / DatabaseIndexing.java
index f8a19504c8dc0165f38ddb34f27b7b31fe8a38ed..bf7293e50dfaf9162f3fa10133738750bfba15ad 100644 (file)
@@ -12,6 +12,7 @@
 package org.simantics.db.indexing;
 
 import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
@@ -117,8 +118,12 @@ public final class DatabaseIndexing {
             // Mark change only once per DB session.
             if (getIndexChangedWriter(session).markDirty(changedFile)) {
                 Files.createDirectories(indexPath);
-                Files.createFile(changedFile);
-                FileUtils.sync(changedFile);
+                if (!Files.exists(changedFile)) {
+                    Files.createFile(changedFile);
+                    FileUtils.sync(changedFile);
+                } else if (!Files.isRegularFile(changedFile)) {
+                    throw new FileAlreadyExistsException(changedFile.toString(), null, "index dirtyness indicator file already exists but it is not a regular file");
+                }
             }
         } catch (IOException e) {
             LOGGER.error("Could not mark index changed for indexPath={} and changedFile={}", indexPath.toAbsolutePath(), changedFile.toAbsolutePath());
@@ -194,7 +199,7 @@ public final class DatabaseIndexing {
             // Make sure that index-base is a valid directory
             if (LOGGER.isDebugEnabled())
                 LOGGER.debug(indexBase + " is not a directory! Removing it.");
-            FileUtils.delete(indexBase);
+            FileUtils.emptyDirectory(indexBase);
             Files.createDirectories(indexBase);
             return;
         }