lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dna...@apache.org
Subject svn commit: r168213 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/store/FSDirectory.java
Date Wed, 04 May 2005 23:34:53 GMT
Author: dnaber
Date: Wed May  4 16:34:52 2005
New Revision: 168213

URL: http://svn.apache.org/viewcvs?rev=168213&view=rev
Log:
only delete our own files when re-creating an index (#34695)

Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/CHANGES.txt?rev=168213&r1=168212&r2=168213&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Wed May  4 16:34:52 2005
@@ -32,6 +32,11 @@
     ranking across multiple indices not to be equivalent.
     (Chuck Williams, Wolf Siberski via Otis, bug #31841)
 
+ 5. When opening an IndexWriter with create=true, Lucene now only deletes
+    its own files from the index directory (looking at the file name suffixes
+    to decide if a file belongs to Lucene). The old behavior was to delete
+    all files. (Daniel Naber, bug #34695)
+ 
 New features
 
  1. Added support for stored compressed fields (patch #31149)

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?rev=168213&r1=168212&r2=168213&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Wed May  4 16:34:52
2005
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 
+import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.File;
 import java.io.RandomAccessFile;
@@ -36,6 +37,36 @@
  * @author Doug Cutting
  */
 public class FSDirectory extends Directory {
+
+  /**
+   * Filter that only accepts filenames created by Lucene.
+   */
+  private class LuceneFileFilter implements FilenameFilter {
+
+    /* (non-Javadoc)
+     * @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
+     */
+    public boolean accept(File dir, String name) {
+      if (name.endsWith(".cfs")) return true;
+      else if (name.endsWith(".fnm")) return true;
+      else if (name.endsWith(".fdt")) return true;
+      else if (name.endsWith(".fdx")) return true;
+      else if (name.endsWith(".frq")) return true;
+      else if (name.endsWith(".prx")) return true;
+      else if (name.endsWith(".tii")) return true;
+      else if (name.endsWith(".tis")) return true;
+      else if (name.endsWith(".tvd")) return true;
+      else if (name.endsWith(".tvf")) return true;
+      else if (name.endsWith(".tvx")) return true;
+      else if (name.endsWith(".del")) return true;
+      else if (name.equals("deletable")) return true;
+      else if (name.equals("segments")) return true;
+      else if (name.matches(".+\\.f\\d+")) return true;
+      return false;
+    }
+
+  }
+
   /** This cache of directories ensures that there is a unique Directory
    * instance per path, so that synchronization on the Directory can be used to
    * synchronize access between readers and writers.
@@ -157,7 +188,7 @@
       if (!directory.mkdirs())
         throw new IOException("Cannot create directory: " + directory);
 
-    String[] files = directory.list();            // clear old files
+    String[] files = directory.list(new LuceneFileFilter());            // clear old files
     for (int i = 0; i < files.length; i++) {
       File file = new File(directory, files[i]);
       if (!file.delete())



Mime
View raw message