Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-638

Can't put non-index files (e.g. CVS, SVN directories) in a Lucene index directory

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Lucene won't tolerate foreign files in its index directories. This makes it impossible to keep an index in a CVS or Subversion repository.

      For instance, this exception appears when creating a RAMDirectory from a java.io.File that contains a subdirectory called ".svn".

      java.io.FileNotFoundException: /home/local/ejj/ic/.caches/.search/.index/.svn
      (Is a directory)
      at java.io.RandomAccessFile.open(Native Method)
      at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
      at
      org.apache.lucene.store.FSIndexInput$Descriptor.<init>(FSDirectory.java:425)
      at org.apache.lucene.store.FSIndexInput.<init>(FSDirectory.java:434)
      at org.apache.lucene.store.FSDirectory.openInput(FSDirectory.java:324)
      at org.apache.lucene.store.RAMDirectory.<init>(RAMDirectory.java:61)
      at org.apache.lucene.store.RAMDirectory.<init>(RAMDirectory.java:86)

      1. LuceneTest.java
        3 kB
        Eleanor Joslin

        Activity

        Hide
        lucenebugs@danielnaber.de Daniel Naber added a comment -

        Thanks, this has now been fixed in trunk.

        Show
        lucenebugs@danielnaber.de Daniel Naber added a comment - Thanks, this has now been fixed in trunk.
        Hide
        simonwillnauer Simon Willnauer added a comment -

        The RAMDirectory class uses the Directory.list() method to create the index input in the constructor. The implementation of FSDirectory returns all containing files of the directory including non lucene files and also all containing directories.
        In my opinion this method should not return non lucene files and directories for consistency.
        The problem does only appear if you create a RamDirectory from a existing index.

        here is the patch for the trunk:
        (I also added a try / finally block in the rename() method to close all streams in the case of an exception on the input stream the output stream would remain open.)
        All test passed, almost no tests in the store package .

        Index: FSDirectory.java
        ===================================================================
        — FSDirectory.java (revision 426479)
        +++ FSDirectory.java (working copy)
        @@ -211,9 +211,9 @@
        }
        }

        • /** Returns an array of strings, one for each file in the directory. */
          + /** Returns an array of strings, one for each lucnene index file in the directory. */
          public String[] list() { - return directory.list(); + return directory.list(new IndexFileNameFilter()); }

        /** Returns true iff a file with the given name exists. */
        @@ -296,20 +296,23 @@
        throw newExc;
        }
        finally {

        • if (in != null) {
        • try { - in.close(); - }

          catch (IOException e) {

        • throw new RuntimeException("Cannot close input stream: " + e.toString(), e);
          + try{
          + if (in != null)
          Unknown macro: { + try { + in.close(); + } catch (IOException e) { + throw new RuntimeException("Cannot close input stream: " + e.toString(), e); + } }
        • }
        • if (out != null) {
        • try { - out.close(); - }

          catch (IOException e)

          { - throw new RuntimeException("Cannot close output stream: " + e.toString(), e); + }

          finally{
          + if (out != null)

          Unknown macro: { + try { + out.close(); + } catch (IOException e) { + throw new RuntimeException("Cannot close output stream: " + e.toString(), e); + } }
        • }
          + }
          }
          }
          }
        Show
        simonwillnauer Simon Willnauer added a comment - The RAMDirectory class uses the Directory.list() method to create the index input in the constructor. The implementation of FSDirectory returns all containing files of the directory including non lucene files and also all containing directories. In my opinion this method should not return non lucene files and directories for consistency. The problem does only appear if you create a RamDirectory from a existing index. here is the patch for the trunk: (I also added a try / finally block in the rename() method to close all streams in the case of an exception on the input stream the output stream would remain open.) All test passed, almost no tests in the store package . Index: FSDirectory.java =================================================================== — FSDirectory.java (revision 426479) +++ FSDirectory.java (working copy) @@ -211,9 +211,9 @@ } } /** Returns an array of strings, one for each file in the directory. */ + /** Returns an array of strings, one for each lucnene index file in the directory. */ public String[] list() { - return directory.list(); + return directory.list(new IndexFileNameFilter()); } /** Returns true iff a file with the given name exists. */ @@ -296,20 +296,23 @@ throw newExc; } finally { if (in != null) { try { - in.close(); - } catch (IOException e) { throw new RuntimeException("Cannot close input stream: " + e.toString(), e); + try{ + if (in != null) Unknown macro: { + try { + in.close(); + } catch (IOException e) { + throw new RuntimeException("Cannot close input stream: " + e.toString(), e); + } } } if (out != null) { try { - out.close(); - } catch (IOException e) { - throw new RuntimeException("Cannot close output stream: " + e.toString(), e); + } finally{ + if (out != null) Unknown macro: { + try { + out.close(); + } catch (IOException e) { + throw new RuntimeException("Cannot close output stream: " + e.toString(), e); + } } } + } } } }
        Hide
        eleanor Eleanor Joslin added a comment -

        Here's an example. Compile and run this with lucene-core-2.0.0.jar in the classpath.

        Show
        eleanor Eleanor Joslin added a comment - Here's an example. Compile and run this with lucene-core-2.0.0.jar in the classpath.
        Hide
        lucenebugs@danielnaber.de Daniel Naber added a comment -

        What exactly does your code look like? Something else must be wrong because I use an index that's committed to CVS without problems (using Lucene 2.0).

        Show
        lucenebugs@danielnaber.de Daniel Naber added a comment - What exactly does your code look like? Something else must be wrong because I use an index that's committed to CVS without problems (using Lucene 2.0).

          People

          • Assignee:
            Unassigned
            Reporter:
            eleanor Eleanor Joslin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development