jgallery
  1. jgallery
  2. JGALLERY-4

Subdirectory support under linux doesn't always work

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: Linux
      Platform: All

    • Issuezilla Id:
      4

      Description

      Subdirectory support under linux doesn't always work. The problem is in
      Folder.loadFolder() which does this:

      imageFiles = directory.list(new FilenameFilter() { ...

      the results of .list() are not guaranteed to be sorted. On windows you get
      alphabetical sort with directories at the start, but in linux they come back in
      inode order I think.

      The code for handling subdirectories presumes they are at the start of the list,
      so on linux fetching a directory that contains subdirectories and images can
      fail with an exception (it tries to create an Image object out of an actual
      directory).

      The following code fixes the problem by using directory.listFiles, explicitly
      sorts the results alphabetically and puts directories first.

      replace:

      imageFiles = directory.list(new FilenameFilter() {
      public boolean accept(File dir, String name)

      { File f1 = new File(dir, name); return (f1.isDirectory() && !thumbsdir.equals(name)) | isJPEGExtension(name); // return isJPEGExtension(name); };
      });

      with this:

      File realImageFiles[] = directory.listFiles(new FilenameFilter() {
      public boolean accept(File dir, String name) { File f1 = new File(dir, name); return (f1.isDirectory() && !thumbsdir.equals(name)) | isJPEGExtension(name); // return isJPEGExtension(name); }

      ;
      });

      Arrays.sort(realImageFiles, new Comparator() {
      public int compare(Object o1, Object o2) {
      File f1 = (File) o1;
      File f2 = (File) o2;
      if ((f1.isDirectory() && f2.isDirectory()) || (f1.isFile() &&
      f2.isFile()))

      { // files are matching type so compare alphabetically return (f1.getName().compareTo(f2.getName())); }

      else {
      // directories come first
      if (f1.isDirectory())

      { return -1; }

      else

      { return 1; }

      }
      }
      });

      imageFiles = new String[realImageFiles.length];
      for (int m = 0; m < realImageFiles.length; m++) {
      imageFiles[m] = realImageFiles[m].getName();
      //log.debug("discovered imageFile " + m + " " + imageFiles[m]);
      }

      Tested on RHEL3.0 with Sun JDK 1.5.0_07 and WinXP with Sun JDK 1.4.2_10.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            jgallery-issues
            Reporter:
            pgleghorn
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: