lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r497612 - in /lucene/java/trunk: ./ src/demo/org/apache/lucene/demo/ src/java/org/apache/lucene/index/ src/java/org/apache/lucene/store/ src/test/org/apache/lucene/ src/test/org/apache/lucene/index/ src/test/org/apache/lucene/index/store/ s...
Date Thu, 18 Jan 2007 22:47:04 GMT
Author: mikemccand
Date: Thu Jan 18 14:47:03 2007
New Revision: 497612

URL: http://svn.apache.org/viewvc?view=rev&rev=497612
Log:
LUCENE-773: deprecate "create" argument to
FSDirectory.getDirectory(*); use IndexWriter's "create" argument
instead

Added:
    lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexModifier.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
    lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
    lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java
    lucene/java/trunk/src/test/org/apache/lucene/StoreTest.java
    lucene/java/trunk/src/test/org/apache/lucene/ThreadSafetyTest.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexModifier.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
    lucene/java/trunk/src/test/org/apache/lucene/index/store/TestRAMDirectory.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
    lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Jan 18 14:47:03 2007
@@ -184,6 +184,11 @@
 
 15. Added isOptimized() method to IndexReader.
     (Otis Gospodnetic)
+
+16. LUCENE-773: Deprecate the FSDirectory.getDirectory(*) methods that
+    take a boolean "create" argument.  Instead you should use
+    IndexWriter's "create" argument to create a new index.
+    (Mike McCandless)
     
 Bug fixes
 

Modified: lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java (original)
+++ lucene/java/trunk/src/demo/org/apache/lucene/demo/DeleteFiles.java Thu Jan 18 14:47:03
2007
@@ -37,7 +37,7 @@
       System.exit(1);
     }
     try {
-      Directory directory = FSDirectory.getDirectory("index", false);
+      Directory directory = FSDirectory.getDirectory("index");
       IndexReader reader = IndexReader.open(directory);
 
       Term term = new Term("path", args[0]);

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexModifier.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexModifier.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexModifier.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexModifier.java Thu Jan 18 14:47:03
2007
@@ -121,7 +121,7 @@
    * 	<code>false</code> to append to the existing index
    */
   public IndexModifier(String dirName, Analyzer analyzer, boolean create) throws IOException
{
-    Directory dir = FSDirectory.getDirectory(dirName, create);
+    Directory dir = FSDirectory.getDirectory(dirName);
     init(dir, analyzer, create);
   }
 
@@ -134,7 +134,7 @@
    * 	<code>false</code> to append to the existing index
    */
   public IndexModifier(File file, Analyzer analyzer, boolean create) throws IOException {
-    Directory dir = FSDirectory.getDirectory(file, create);
+    Directory dir = FSDirectory.getDirectory(file);
     init(dir, analyzer, create);
   }
 

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexReader.java Thu Jan 18 14:47:03
2007
@@ -128,13 +128,13 @@
   /** Returns an IndexReader reading the index in an FSDirectory in the named
    path. */
   public static IndexReader open(String path) throws IOException {
-    return open(FSDirectory.getDirectory(path, false), true);
+    return open(FSDirectory.getDirectory(path), true);
   }
 
   /** Returns an IndexReader reading the index in an FSDirectory in the named
    path. */
   public static IndexReader open(File path) throws IOException {
-    return open(FSDirectory.getDirectory(path, false), true);
+    return open(FSDirectory.getDirectory(path), true);
   }
 
   /** Returns an IndexReader reading the index in the given Directory. */
@@ -240,7 +240,7 @@
    * @throws IOException if segments file cannot be read
    */
   public static long getCurrentVersion(File directory) throws IOException {
-    Directory dir = FSDirectory.getDirectory(directory, false);
+    Directory dir = FSDirectory.getDirectory(directory);
     long version = getCurrentVersion(dir);
     dir.close();
     return version;
@@ -767,7 +767,7 @@
    * @throws IOException if there is a problem with accessing the index
    */
   public static boolean isLocked(String directory) throws IOException {
-    Directory dir = FSDirectory.getDirectory(directory, false);
+    Directory dir = FSDirectory.getDirectory(directory);
     boolean result = isLocked(dir);
     dir.close();
     return result;
@@ -815,7 +815,7 @@
       File file = new File(filename);
       String dirname = file.getAbsoluteFile().getParent();
       filename = file.getName();
-      dir = FSDirectory.getDirectory(dirname, false);
+      dir = FSDirectory.getDirectory(dirname);
       cfr = new CompoundFileReader(dir, filename);
 
       String [] files = cfr.list();

Modified: lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/index/IndexWriter.java Thu Jan 18 14:47:03
2007
@@ -36,23 +36,27 @@
 /**
   An IndexWriter creates and maintains an index.
 
-  The third argument to the 
+  <p>The third argument (<code>create</code>) to the 
   <a href="#IndexWriter(org.apache.lucene.store.Directory, org.apache.lucene.analysis.Analyzer,
boolean)"><b>constructor</b></a>
   determines whether a new index is created, or whether an existing index is
-  opened for the addition of new documents.
+  opened for the addition of new documents.  Note that you
+  can open an index with create=true even while readers are
+  using the index.  The old readers will continue to search
+  the "point in time" snapshot they had opened, and won't
+  see the newly created index until they re-open.</p>
 
-  In either case, documents are added with the <a
+  <p>In either case, documents are added with the <a
   href="#addDocument(org.apache.lucene.document.Document)"><b>addDocument</b></a>
method.  
-  When finished adding documents, <a href="#close()"><b>close</b></a>
should be called.
+  When finished adding documents, <a href="#close()"><b>close</b></a>
should be called.</p>
 
   <p>If an index will not have more documents added for a while and optimal search
   performance is desired, then the <a href="#optimize()"><b>optimize</b></a>
-  method should be called before the index is closed.
+  method should be called before the index is closed.</p>
   
   <p>Opening an IndexWriter creates a lock file for the directory in use. Trying to
open
   another IndexWriter on the same directory will lead to an IOException. The IOException
   is also thrown if an IndexReader on the same directory is used to delete documents
-  from the index.
+  from the index.</p>
   
   @see IndexModifier IndexModifier supports the important methods of IndexWriter plus deletion
   */
@@ -313,12 +317,12 @@
 
   private void init(String path, Analyzer a, final boolean create)
     throws IOException {
-    init(FSDirectory.getDirectory(path, create, null, false), a, create, true);
+    init(FSDirectory.getDirectory(path), a, create, true);
   }
 
   private void init(File path, Analyzer a, final boolean create)
     throws IOException {
-    init(FSDirectory.getDirectory(path, create, null, false), a, create, true);
+    init(FSDirectory.getDirectory(path), a, create, true);
   }
 
   private void init(Directory d, Analyzer a, final boolean create, boolean closeDir)
@@ -326,6 +330,11 @@
     this.closeDir = closeDir;
     directory = d;
     analyzer = a;
+
+    if (create) {
+      // Clear the write lock in case it's leftover:
+      directory.getLockFactory().clearLock(IndexWriter.WRITE_LOCK_NAME);
+    }
 
     Lock writeLock = directory.makeLock(IndexWriter.WRITE_LOCK_NAME);
     if (!writeLock.obtain(writeLockTimeout)) // obtain write lock

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/FSDirectory.java Thu Jan 18 14:47:03
2007
@@ -28,7 +28,7 @@
 
 import org.apache.lucene.index.IndexFileNameFilter;
 
-// Used only for WRITE_LOCK_NAME:
+// Used only for WRITE_LOCK_NAME in deprecated create=true case:
 import org.apache.lucene.index.IndexWriter;
 
 /**
@@ -39,6 +39,11 @@
  * <code>org.apache.lucene.store.FSDirectoryLockFactoryClass</code> Java system
  * property, or by calling {@link #setLockFactory} after creating
  * the Directory.
+
+ * <p>Directories are cached, so that, for a given canonical
+ * path, the same FSDirectory instance will always be
+ * returned by <code>getDirectory</code>.  This permits
+ * synchronization on directories.</p>
  *
  * @see Directory
  * @author Doug Cutting
@@ -89,8 +94,7 @@
    * etc.) passing in your preferred lock directory.  Then,
    * pass this <code>LockFactory</code> instance to one of
    * the <code>getDirectory</code> methods that take a
-   * <code>lockFactory</code> (for example, {@link
-   * #getDirectory(String, boolean, LockFactory)}).
+   * <code>lockFactory</code> (for example, {@link #getDirectory(String, LockFactory)}).
    */
   public static final String LOCK_DIR = System.getProperty("org.apache.lucene.lockDir",
                                                            System.getProperty("java.io.tmpdir"));
@@ -128,73 +132,48 @@
   private byte[] buffer = null;
 
   /** Returns the directory instance for the named location.
-   *
-   * <p>Directories are cached, so that, for a given canonical path, the same
-   * FSDirectory instance will always be returned.  This permits
-   * synchronization on directories.
-   *
    * @param path the path to the directory.
-   * @param create if true, create, or erase any existing contents.
    * @return the FSDirectory for the named file.  */
-  public static FSDirectory getDirectory(String path, boolean create)
+  public static FSDirectory getDirectory(String path)
       throws IOException {
-    return getDirectory(new File(path), create, null, true);
+    return getDirectory(new File(path), null);
   }
 
-  /** Returns the directory instance for the named location, using the
-   * provided LockFactory implementation.
-   *
-   * <p>Directories are cached, so that, for a given canonical path, the same
-   * FSDirectory instance will always be returned.  This permits
-   * synchronization on directories.
-   *
+  /** Returns the directory instance for the named location.
    * @param path the path to the directory.
-   * @param create if true, create, or erase any existing contents.
    * @param lockFactory instance of {@link LockFactory} providing the
    *        locking implementation.
    * @return the FSDirectory for the named file.  */
-  public static FSDirectory getDirectory(String path, boolean create,
-                                         LockFactory lockFactory, boolean doRemoveOldFiles)
-      throws IOException {
-    return getDirectory(new File(path), create, lockFactory, doRemoveOldFiles);
-  }
-
-  public static FSDirectory getDirectory(String path, boolean create,
-                                         LockFactory lockFactory)
+  public static FSDirectory getDirectory(String path, LockFactory lockFactory)
       throws IOException {
-    return getDirectory(new File(path), create, lockFactory, true);
+    return getDirectory(new File(path), lockFactory);
   }
 
   /** Returns the directory instance for the named location.
-   *
-   * <p>Directories are cached, so that, for a given canonical path, the same
-   * FSDirectory instance will always be returned.  This permits
-   * synchronization on directories.
-   *
    * @param file the path to the directory.
-   * @param create if true, create, or erase any existing contents.
    * @return the FSDirectory for the named file.  */
-  public static FSDirectory getDirectory(File file, boolean create, boolean doRemoveOldFiles)
+  public static FSDirectory getDirectory(File file)
     throws IOException {
-    return getDirectory(file, create, null, doRemoveOldFiles);
+    return getDirectory(file, null);
   }
 
-  /** Returns the directory instance for the named location, using the
-   * provided LockFactory implementation.
-   *
-   * <p>Directories are cached, so that, for a given canonical path, the same
-   * FSDirectory instance will always be returned.  This permits
-   * synchronization on directories.
-   *
+  /** Returns the directory instance for the named location.
    * @param file the path to the directory.
-   * @param create if true, create, or erase any existing contents.
-   * @param lockFactory instance of  {@link LockFactory} providing the
+   * @param lockFactory instance of {@link LockFactory} providing the
    *        locking implementation.
    * @return the FSDirectory for the named file.  */
-  public static FSDirectory getDirectory(File file, boolean create,
-                                         LockFactory lockFactory, boolean doRemoveOldFiles)
-    throws IOException {
+  public static FSDirectory getDirectory(File file, LockFactory lockFactory)
+    throws IOException
+  {
     file = new File(file.getCanonicalPath());
+
+    if (file.exists() && !file.isDirectory())
+      throw new IOException(file + " not a directory");
+
+    if (!file.exists())
+      if (!file.mkdirs())
+        throw new IOException("Cannot create directory: " + file);
+
     FSDirectory dir;
     synchronized (DIRECTORIES) {
       dir = (FSDirectory)DIRECTORIES.get(file);
@@ -204,19 +183,14 @@
         } catch (Exception e) {
           throw new RuntimeException("cannot load FSDirectory class: " + e.toString(), e);
         }
-        dir.init(file, create, lockFactory, doRemoveOldFiles);
+        dir.init(file, lockFactory);
         DIRECTORIES.put(file, dir);
       } else {
-
         // Catch the case where a Directory is pulled from the cache, but has a
         // different LockFactory instance.
         if (lockFactory != null && lockFactory != dir.getLockFactory()) {
           throw new IOException("Directory was previously created with a different LockFactory
instance; please pass null as the lockFactory instance and use setLockFactory to change it");
         }
-
-        if (create) {
-          dir.create(doRemoveOldFiles);
-        }
       }
     }
     synchronized (dir) {
@@ -225,16 +199,54 @@
     return dir;
   }
 
-  public static FSDirectory getDirectory(File file, boolean create,
-                                         LockFactory lockFactory)
+
+  /** Returns the directory instance for the named location.
+   *
+   * @deprecated Use IndexWriter's create flag, instead, to
+   * create a new index.
+   *
+   * @param path the path to the directory.
+   * @param create if true, create, or erase any existing contents.
+   * @return the FSDirectory for the named file.  */
+  public static FSDirectory getDirectory(String path, boolean create)
+      throws IOException {
+    return getDirectory(new File(path), create);
+  }
+
+  /** Returns the directory instance for the named location.
+   *
+   * @deprecated Use IndexWriter's create flag, instead, to
+   * create a new index.
+   *
+   * @param file the path to the directory.
+   * @param create if true, create, or erase any existing contents.
+   * @return the FSDirectory for the named file.  */
+  public static FSDirectory getDirectory(File file, boolean create)
     throws IOException
   {
-    return getDirectory(file, create, lockFactory, true);
+    FSDirectory dir = getDirectory(file, null);
+
+    // This is now deprecated (creation should only be done
+    // by IndexWriter):
+    if (create) {
+      dir.create();
+    }
+
+    return dir;
   }
 
-  public static FSDirectory getDirectory(File file, boolean create)
-    throws IOException {
-    return getDirectory(file, create, true);
+  private void create() throws IOException {
+    if (directory.exists()) {
+      String[] files = directory.list(IndexFileNameFilter.getFilter());            // clear
old files
+      if (files == null)
+        throw new IOException("Cannot read directory " + directory.getAbsolutePath());
+      for (int i = 0; i < files.length; i++) {
+        File file = new File(directory, files[i]);
+        if (!file.delete())
+          throw new IOException("Cannot delete " + file);
+      }
+    }
+    lockFactory.clearLock(IndexWriter.WRITE_LOCK_NAME);
   }
 
   private File directory = null;
@@ -242,24 +254,15 @@
 
   protected FSDirectory() {};                     // permit subclassing
 
-  private void init(File path, boolean create, boolean doRemoveOldFiles) throws IOException
{
-    directory = path;
-
-    if (create) {
-      create(doRemoveOldFiles);
-    }
-
-    if (!directory.isDirectory())
-      throw new IOException(path + " not a directory");
-  }
-
-  private void init(File path, boolean create, LockFactory lockFactory, boolean doRemoveOldFiles)
throws IOException {
+  private void init(File path, LockFactory lockFactory) throws IOException {
 
     // Set up lockFactory with cascaded defaults: if an instance was passed in,
     // use that; else if locks are disabled, use NoLockFactory; else if the
     // system property org.apache.lucene.store.FSDirectoryLockFactoryClass is set,
     // instantiate that; else, use SimpleFSLockFactory:
 
+    directory = path;
+
     boolean doClearLockID = false;
 
     if (lockFactory == null) {
@@ -297,43 +300,13 @@
       }
     }
 
-    // Must initialize directory here because setLockFactory uses it
-    // (when the LockFactory calls getLockID).  But we want to create
-    // the lockFactory before calling init() because init() needs to
-    // use the lockFactory to clear old locks.  So this breaks
-    // chicken/egg:
-    directory = path;
-
     setLockFactory(lockFactory);
+
     if (doClearLockID) {
       // Clear the prefix because write.lock will be
       // stored in our directory:
       lockFactory.setLockPrefix(null);
     }
-
-    init(path, create, doRemoveOldFiles);
-  }
-
-  private synchronized void create(boolean doRemoveOldFiles) throws IOException {
-    if (!directory.exists())
-      if (!directory.mkdirs())
-        throw new IOException("Cannot create directory: " + directory);
-
-    if (!directory.isDirectory())
-      throw new IOException(directory + " not a directory");
-
-    if (doRemoveOldFiles) {
-      String[] files = directory.list(IndexFileNameFilter.getFilter());            // clear
old files
-      if (files == null)
-        throw new IOException("Cannot read directory " + directory.getAbsolutePath());
-      for (int i = 0; i < files.length; i++) {
-        File file = new File(directory, files[i]);
-        if (!file.delete())
-          throw new IOException("Cannot delete " + file);
-      }
-    }
-
-    lockFactory.clearLock(IndexWriter.WRITE_LOCK_NAME);
   }
 
   /** Returns an array of strings, one for each Lucene index file in the directory. */
@@ -445,6 +418,7 @@
   /** Creates a new, empty file in the directory with the given name.
       Returns a stream writing this file. */
   public IndexOutput createOutput(String name) throws IOException {
+
     File file = new File(directory, name);
     if (file.exists() && !file.delete())          // delete existing, if any
       throw new IOException("Cannot overwrite: " + file);

Modified: lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/store/RAMDirectory.java Thu Jan 18 14:47:03
2007
@@ -107,7 +107,7 @@
    * @see #RAMDirectory(Directory)
    */
   public RAMDirectory(File dir) throws IOException {
-    this(FSDirectory.getDirectory(dir, false), true);
+    this(FSDirectory.getDirectory(dir), true);
   }
 
   /**
@@ -118,7 +118,7 @@
    * @see #RAMDirectory(Directory)
    */
   public RAMDirectory(String dir) throws IOException {
-    this(FSDirectory.getDirectory(dir, false), true);
+    this(FSDirectory.getDirectory(dir), true);
   }
 
   /** Returns an array of strings, one for each file in the directory. */

Modified: lucene/java/trunk/src/test/org/apache/lucene/StoreTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/StoreTest.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/StoreTest.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/StoreTest.java Thu Jan 18 14:47:03 2007
@@ -22,6 +22,7 @@
 import org.apache.lucene.store.IndexOutput;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util._TestUtil;
 
 import java.util.Date;
 import java.util.Random;
@@ -46,8 +47,11 @@
     Directory store;
     if (ram)
       store = new RAMDirectory();
-    else
-      store = FSDirectory.getDirectory("test.store", true);
+    else {
+      String dirName = "test.store";
+      _TestUtil.rmDir(dirName);
+      store = FSDirectory.getDirectory(dirName);
+    }
 
     final int LENGTH_MASK = 0xFFF;
 
@@ -84,7 +88,7 @@
     start = new Date();
 
     if (!ram)
-      store = FSDirectory.getDirectory("test.store", false);
+      store = FSDirectory.getDirectory("test.store");
 
     for (i = 0; i < count; i++) {
       String name = i + ".dat";

Modified: lucene/java/trunk/src/test/org/apache/lucene/ThreadSafetyTest.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/ThreadSafetyTest.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/ThreadSafetyTest.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/ThreadSafetyTest.java Thu Jan 18 14:47:03
2007
@@ -139,7 +139,7 @@
     File indexDir = new File("index");
     if (! indexDir.exists()) indexDir.mkdirs();
     
-    IndexReader.unlock(FSDirectory.getDirectory(indexDir, false));
+    IndexReader.unlock(FSDirectory.getDirectory(indexDir));
 
     if (!readOnly) {
       IndexWriter writer = new IndexWriter(indexDir, ANALYZER, !add);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java Thu
Jan 18 14:47:03 2007
@@ -119,7 +119,7 @@
     //QueryParser parser = new QueryParser("contents", new WhitespaceAnalyzer());
     //Query query = parser.parse("handle:1");
 
-    Directory dir = FSDirectory.getDirectory(dirName, false);
+    Directory dir = FSDirectory.getDirectory(dirName);
     IndexSearcher searcher = new IndexSearcher(dir);
     
     Hits hits = searcher.search(new TermQuery(new Term("content", "aaa")));
@@ -137,7 +137,7 @@
    * setNorm, and search */
   public void changeIndexWithAdds(String dirName) throws IOException {
 
-    Directory dir = FSDirectory.getDirectory(dirName, false);
+    Directory dir = FSDirectory.getDirectory(dirName);
     // open writer
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
 
@@ -194,7 +194,7 @@
    * setNorm, and search */
   public void changeIndexNoAdds(String dirName) throws IOException {
 
-    Directory dir = FSDirectory.getDirectory(dirName, false);
+    Directory dir = FSDirectory.getDirectory(dirName);
 
     // make sure searching sees right # hits
     IndexSearcher searcher = new IndexSearcher(dir);
@@ -238,7 +238,7 @@
 
   public void createIndex(String dirName, boolean doCFS) throws IOException {
 
-    Directory dir = FSDirectory.getDirectory(dirName, true);
+    Directory dir = FSDirectory.getDirectory(dirName);
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
     writer.setUseCompoundFile(doCFS);
     
@@ -265,7 +265,7 @@
   public void testExactFileNames() throws IOException {
 
     String outputDir = "lucene.backwardscompat0.index";
-    Directory dir = FSDirectory.getDirectory(outputDir, true);
+    Directory dir = FSDirectory.getDirectory(outputDir);
     IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
     for(int i=0;i<35;i++) {
       addDoc(writer, i);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestCompoundFile.java Thu Jan 18 14:47:03
2007
@@ -28,6 +28,7 @@
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store._TestHelper;
+import org.apache.lucene.util._TestUtil;
 
 
 /**
@@ -58,8 +59,9 @@
 
 
     public void setUp() throws IOException {
-        //dir = new RAMDirectory();
-        dir = FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"),
true);
+       File file = new File(System.getProperty("tempDir"), "testIndex");
+       _TestUtil.rmDir(file);
+       dir = FSDirectory.getDirectory(file);
     }
 
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestFieldsReader.java Thu Jan 18 14:47:03
2007
@@ -36,6 +36,7 @@
 import org.apache.lucene.search.Similarity;
 import org.apache.lucene.store.FSDirectory;
 import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.util._TestUtil;
 
 public class TestFieldsReader extends TestCase {
   private RAMDirectory dir = new RAMDirectory();
@@ -167,7 +168,8 @@
     String userName = System.getProperty("user.name");
     String path = tmpIODir + File.separator + "lazyDir" + userName;
     File file = new File(path);
-    FSDirectory tmpDir = FSDirectory.getDirectory(file, true);
+    _TestUtil.rmDir(file);
+    FSDirectory tmpDir = FSDirectory.getDirectory(file);
     assertTrue(tmpDir != null);
     DocumentWriter writer = new DocumentWriter(tmpDir, new WhitespaceAnalyzer(),
             Similarity.getDefault(), 50);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexModifier.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexModifier.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexModifier.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexModifier.java Thu Jan 18 14:47:03
2007
@@ -146,7 +146,7 @@
     if (tempDir == null)
       throw new IOException("java.io.tmpdir undefined, cannot run test");
     File indexDir = new File(tempDir, "lucenetestindex");
-    Directory rd = FSDirectory.getDirectory(indexDir, create);
+    Directory rd = FSDirectory.getDirectory(indexDir);
     IndexThread.id = 0;
     IndexThread.idStack.clear();
     IndexModifier index = new IndexModifier(rd, new StandardAnalyzer(), create);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexReader.java Thu Jan 18 14:47:03
2007
@@ -33,6 +33,7 @@
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Hits;
 import org.apache.lucene.search.TermQuery;
+import org.apache.lucene.util._TestUtil;
 
 import java.util.Collection;
 import java.util.Arrays;
@@ -253,7 +254,7 @@
             throw new IOException("tempDir undefined, cannot run test");
 
         File indexDir = new File(tempDir, "lucenetestnormwriter");
-        Directory dir = FSDirectory.getDirectory(indexDir, true);
+        Directory dir = FSDirectory.getDirectory(indexDir);
         IndexWriter writer = null;
         IndexReader reader = null;
         Term searchTerm = new Term("content", "aaa");
@@ -320,7 +321,7 @@
     private void deleteReaderWriterConflict(boolean optimize) throws IOException
     {
         //Directory dir = new RAMDirectory();
-        Directory dir = getDirectory(true);
+        Directory dir = getDirectory();
 
         Term searchTerm = new Term("content", "aaa");
         Term searchTerm2 = new Term("content", "bbb");
@@ -400,21 +401,23 @@
         reader.close();
     }
 
-  private Directory getDirectory(boolean create) throws IOException {
-    return FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"),
create);
+  private Directory getDirectory() throws IOException {
+    return FSDirectory.getDirectory(new File(System.getProperty("tempDir"), "testIndex"));
   }
 
   public void testFilesOpenClose() throws IOException
     {
         // Create initial data set
-        Directory dir = getDirectory(true);
+        File dirFile = new File(System.getProperty("tempDir"), "testIndex");
+        Directory dir = getDirectory();
         IndexWriter writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
         addDoc(writer, "test");
         writer.close();
         dir.close();
 
         // Try to erase the data - this ensures that the writer closed all files
-        dir = getDirectory(true);
+        _TestUtil.rmDir(dirFile);
+        dir = getDirectory();
 
         // Now create the data set again, just as before
         writer  = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
@@ -423,13 +426,14 @@
         dir.close();
 
         // Now open existing directory and test that reader closes all files
-        dir = getDirectory(false);
+        dir = getDirectory();
         IndexReader reader1 = IndexReader.open(dir);
         reader1.close();
         dir.close();
 
-        // The following will fail if reader did not close all files
-        dir = getDirectory(true);
+        // The following will fail if reader did not close
+        // all files
+        _TestUtil.rmDir(dirFile);
     }
 
     public void testLastModified() throws IOException {
@@ -833,7 +837,7 @@
 
     private void deleteReaderReaderConflict(boolean optimize) throws IOException
     {
-        Directory dir = getDirectory(true);
+        Directory dir = getDirectory();
 
         Term searchTerm1 = new Term("content", "aaa");
         Term searchTerm2 = new Term("content", "bbb");

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestIndexWriter.java Thu Jan 18 14:47:03
2007
@@ -447,7 +447,7 @@
         File indexDir = new File(tempDir, "lucenetestindexwriter");
 
         try {
-          Directory dir = FSDirectory.getDirectory(indexDir, true);
+          Directory dir = FSDirectory.getDirectory(indexDir);
 
           // add one document & close writer
           IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestNorms.java Thu Jan 18 14:47:03
2007
@@ -65,7 +65,7 @@
     
     // test with a single index: index1
     File indexDir1 = new File(tempDir, "lucenetestindex1");
-    Directory dir1 = FSDirectory.getDirectory(indexDir1, true);
+    Directory dir1 = FSDirectory.getDirectory(indexDir1);
 
     norms = new ArrayList();
     modifiedNorms = new ArrayList();
@@ -83,14 +83,14 @@
     numDocNorms = 0;
     
     File indexDir2 = new File(tempDir, "lucenetestindex2");
-    Directory dir2 = FSDirectory.getDirectory(indexDir2, true);
+    Directory dir2 = FSDirectory.getDirectory(indexDir2);
 
     createIndex(dir2);
     doTestNorms(dir2);
 
     // add index1 and index2 to a third index: index3
     File indexDir3 = new File(tempDir, "lucenetestindex3");
-    Directory dir3 = FSDirectory.getDirectory(indexDir3, true);
+    Directory dir3 = FSDirectory.getDirectory(indexDir3);
 
     createIndex(dir3);
     IndexWriter iw = new IndexWriter(dir3,anlzr,false);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing.java Thu Jan 18
14:47:03 2007
@@ -157,7 +157,7 @@
     // Second in an FSDirectory:
     String tempDir = System.getProperty("java.io.tmpdir");
     File dirPath = new File(tempDir, "lucene.test.stress");
-    directory = FSDirectory.getDirectory(dirPath, true);
+    directory = FSDirectory.getDirectory(dirPath);
     runStressTest(directory);
     directory.close();
     rmDir(dirPath);

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/store/TestRAMDirectory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/store/TestRAMDirectory.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/store/TestRAMDirectory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/store/TestRAMDirectory.java Thu Jan
18 14:47:03 2007
@@ -71,7 +71,7 @@
   
   public void testRAMDirectory () throws IOException {
     
-    Directory dir = FSDirectory.getDirectory(indexDir, false);
+    Directory dir = FSDirectory.getDirectory(indexDir);
     MockRAMDirectory ramDir = new MockRAMDirectory(dir);
     
     // close the underlaying directory

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestLockFactory.java Thu Jan 18 14:47:03
2007
@@ -253,11 +253,11 @@
         String indexDirName = "index.TestLockFactory5";
 
         LockFactory lf = new SingleInstanceLockFactory();
-        FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, true, lf);
+        FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, lf);
 
         // Different lock factory instance should hit IOException:
         try {
-            FSDirectory fs2 = FSDirectory.getDirectory(indexDirName, true, new SingleInstanceLockFactory());
+            FSDirectory fs2 = FSDirectory.getDirectory(indexDirName, new SingleInstanceLockFactory());
             fail("Should have hit an IOException because LockFactory instances differ");
         } catch (IOException e) {
         }
@@ -266,7 +266,7 @@
 
         // Same lock factory instance should not:
         try {
-            fs2 = FSDirectory.getDirectory(indexDirName, true, lf);
+            fs2 = FSDirectory.getDirectory(indexDirName, lf);
         } catch (IOException e) {
             e.printStackTrace(System.out);
             fail("Should not have hit an IOException because LockFactory instances are the
same");
@@ -296,7 +296,7 @@
     }
 
     public void _testStressLocks(LockFactory lockFactory, String indexDirName) throws IOException
{
-        FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, true, lockFactory);
+        FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, lockFactory);
 
         // First create a 1 doc index:
         IndexWriter w = new IndexWriter(fs1, new WhitespaceAnalyzer(), true);
@@ -350,8 +350,8 @@
     public void testNativeFSLockFactoryPrefix() throws IOException {
 
       // Make sure we get identical instances:
-      Directory dir1 = FSDirectory.getDirectory("TestLockFactory.8", true, new NativeFSLockFactory("TestLockFactory.8"));
-      Directory dir2 = FSDirectory.getDirectory("TestLockFactory.9", true, new NativeFSLockFactory("TestLockFactory.9"));
+      Directory dir1 = FSDirectory.getDirectory("TestLockFactory.8", new NativeFSLockFactory("TestLockFactory.8"));
+      Directory dir2 = FSDirectory.getDirectory("TestLockFactory.9", new NativeFSLockFactory("TestLockFactory.9"));
 
       String prefix1 = dir1.getLockFactory().getLockPrefix();
       String prefix2 = dir2.getLockFactory().getLockPrefix();
@@ -366,8 +366,8 @@
     // write.lock is stored in index):
     public void testDefaultFSLockFactoryPrefix() throws IOException {
 
-      // Make sure we get identical instances:
-      Directory dir = FSDirectory.getDirectory("TestLockFactory.10", true);
+      // Make sure we get null prefix:
+      Directory dir = FSDirectory.getDirectory("TestLockFactory.10");
 
       String prefix = dir.getLockFactory().getLockPrefix();
 

Modified: lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java?view=diff&rev=497612&r1=497611&r2=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/store/TestWindowsMMap.java Thu Jan 18 14:47:03
2007
@@ -47,7 +47,7 @@
 
 	public void testMmapIndex() throws Exception {
 		FSDirectory storeDirectory;
-		storeDirectory = FSDirectory.getDirectory(storePathname, true);
+		storeDirectory = FSDirectory.getDirectory(storePathname);
 
 		// plan to add a set of useful stopwords, consider changing some of the
 		// interior filters.

Added: lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java?view=auto&rev=497612
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java (added)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/_TestUtil.java Thu Jan 18 14:47:03 2007
@@ -0,0 +1,23 @@
+
+package org.apache.lucene.util;
+import java.io.File;
+import java.io.IOException;
+
+public class _TestUtil {
+
+  public static void rmDir(File dir) throws IOException {
+    if (dir.exists()) {
+      File[] files = dir.listFiles();
+      for (int i = 0; i < files.length; i++) {
+        if (!files[i].delete()) {
+          throw new IOException("could not delete " + files[i]);
+        }
+      }
+      dir.delete();
+    }
+  }
+
+  public static void rmDir(String dir) throws IOException {
+    rmDir(new File(dir));
+  }
+}



Mime
View raw message