Index: src/test/org/apache/lucene/index/store/TestRAMDirectory.java =================================================================== --- src/test/org/apache/lucene/index/store/TestRAMDirectory.java (revision 388840) +++ src/test/org/apache/lucene/index/store/TestRAMDirectory.java (working copy) @@ -123,7 +123,7 @@ IndexReader reader = IndexReader.open(ramDir); assertEquals(docsToAdd, reader.numDocs()); - // open search zo check if all doc's are there + // open search to check if all doc's are there IndexSearcher searcher = new IndexSearcher(reader); // search for all documents @@ -137,6 +137,25 @@ searcher.close(); } + public void testRAMDirectoryWithGarbage () throws IOException { + + // create some extraneous files and directories + File someFile = new File(indexDir, "some-file"); + someFile.createNewFile(); + File someDir = new File(indexDir, "some-dir"); + someDir.mkdir(); + File someDirHidden = new File(indexDir, ".some-dir"); + someDirHidden.mkdir(); + + // run the directory test + testRAMDirectory(); + + // delete garbage file and directory + someFile.delete(); + someDir.delete(); + someDirHidden.delete(); + } + public void tearDown() { // cleanup if (indexDir != null && indexDir.exists()) { Index: src/java/org/apache/lucene/store/FSDirectory.java =================================================================== --- src/java/org/apache/lucene/store/FSDirectory.java (revision 388840) +++ src/java/org/apache/lucene/store/FSDirectory.java (working copy) @@ -24,6 +24,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Hashtable; +import java.util.ArrayList; import org.apache.lucene.index.IndexFileNameFilter; @@ -210,7 +211,14 @@ /** Returns an array of strings, one for each file in the directory. */ public String[] list() { - return directory.list(); + final File[] files = directory.listFiles(); + ArrayList file_names = new ArrayList(); + for (int i = 0; i < files.length; i++) { + if (!files[i].isDirectory()) { + file_names.add(files[i].getName()); + } + } + return (String[])file_names.toArray(new String[file_names.size()]); } /** Returns true iff a file with the given name exists. */