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

Problem creating directories for FSDirectory

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core/store
    • Labels:
      None
    • Environment:

      Operating System: other
      Platform: All

    • Bugzilla Id:
      6914

      Description

      There is a problem when you try to create a directory (FSDirectory) that doesn't exists and you
      specified a path with a depth greater than 1.

      For example: lucia/index/

      The problem
      lays on the method
      private synchronized void create() throws IOException {
      if
      (!directory.exists())
      directory.mkdir(); <======== HERE SHOULD BE mkdirs();

      String[] files = directory.list(); // clear old files
      for (int i = 0; i < files.length; i++)

      { File file = new File(directory, files[i]); if (!file.delete()) throw new IOException("couldn't delete " + files[i]); }

      }

      Regerds

        Activity

        Hide
        drag0n2@yahoo.com Eugene Gluzberg added a comment -

        Ok above is the fix, someone plz commit it. I suddenly realized I dont have commit
        access!

        Show
        drag0n2@yahoo.com Eugene Gluzberg added a comment - Ok above is the fix, someone plz commit it. I suddenly realized I dont have commit access!
        Hide
        drag0n2@yahoo.com Eugene Gluzberg added a comment -

        Created an attachment (id=1342)
        its the fix for the bug

        Show
        drag0n2@yahoo.com Eugene Gluzberg added a comment - Created an attachment (id=1342) its the fix for the bug
        Hide
        luispenya@aqs.es Luis Peña added a comment -

        Yes, the second solution it's better, so I think.

        Show
        luispenya@aqs.es Luis Peña added a comment - Yes, the second solution it's better, so I think.
        Hide
        drag0n2@yahoo.com Eugene Gluzberg added a comment -

        Well, we should definatelly not keep the current code. It should either read.

        if (!directory.exists())
        throw new IOException("Directory " + directory + " does not exist");

        OR
        if (!directory.exists())
        if ( !directory.mkdirs() )
        throw new IOException("Cannot create directory " + directory);

        I vote for #2, only because its closer to the current behaivor of the code, users that
        expect at least one directory to be created for them will have to change their code...

        Show
        drag0n2@yahoo.com Eugene Gluzberg added a comment - Well, we should definatelly not keep the current code. It should either read. if (!directory.exists()) throw new IOException("Directory " + directory + " does not exist"); OR if (!directory.exists()) if ( !directory.mkdirs() ) throw new IOException("Cannot create directory " + directory); I vote for #2, only because its closer to the current behaivor of the code, users that expect at least one directory to be created for them will have to change their code...
        Hide
        luispenya@aqs.es Luis Peña added a comment -

        Well, I supose that it aids to keep the problem away. But, if you want to create a new index you
        shouldn't know if it exists or not, you only have to said 'I want a new index in this path' and, I
        think, the writer must do all the work.

        With this in mind, I think that a posible solution can
        be that the indexwriter find out if the directory exists or create it.

        Please comments to my
        idea.

        Show
        luispenya@aqs.es Luis Peña added a comment - Well, I supose that it aids to keep the problem away. But, if you want to create a new index you shouldn't know if it exists or not, you only have to said 'I want a new index in this path' and, I think, the writer must do all the work. With this in mind, I think that a posible solution can be that the indexwriter find out if the directory exists or create it. Please comments to my idea.
        Hide
        otis@apache.org Otis Gospodnetic added a comment -

        I would actually vote against both mkdir() and mkdirs() and require that the
        user/developer/application explicitly creates a directory to hold the index
        outside of Lucene.
        What do you think?

        Show
        otis@apache.org Otis Gospodnetic added a comment - I would actually vote against both mkdir() and mkdirs() and require that the user/developer/application explicitly creates a directory to hold the index outside of Lucene. What do you think?

          People

          • Assignee:
            drag0n2@yahoo.com Eugene Gluzberg
            Reporter:
            luispenya@aqs.es Luis Peña
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development