Fop
  1. Fop
  2. FOP-1625

[PATCH] FontCache.getDefaultCacheFile() method returns a non-existant file handle

    Details

    • Type: Bug Bug
    • Status: Closed
    • Resolution: Fixed
    • Affects Version/s: trunk
    • Fix Version/s: None
    • Component/s: fonts
    • Labels:
    • Environment:
      Operating System: Linux
      Platform: PC
    • External issue ID:
      46686

      Description

      Method getDefaultCacheFile() returns an invalid file handle because it doesn't check to see if the directory is writable.

      private static File getUserHome() {
              String s = System.getProperty("user.home");
              if (s != null) {
                  File userDir = new File(s);
                  if (userDir.exists()) {
                      return userDir;
                  }
              }
              return null;
          }
      
      
      /**
           * Returns the default font cache file.
           * @param forWriting true if the user directory should be created
           * @return the default font cache file
           */
          public static File getDefaultCacheFile(boolean forWriting) {
              File userHome = getUserHome();
              if (userHome != null) {
                  File fopUserDir = new File(userHome, FOP_USER_DIR);
                  if (forWriting) {
                      fopUserDir.mkdir();
                  }
                  return new File(fopUserDir, DEFAULT_CACHE_FILENAME);
              }
              return new File(FOP_USER_DIR);
      
      }
      

      The method getUserHome() can return a directory that is not a writable directory. In most cases, the user who is running the webserver has access to user.home, but some in some environments, it is possible that user.home is not writable. Anyway, a simple way to fix it would be to fall back to a the java.io.tmpdir if the userHome is not writable. See attached patch that has that fix

        Activity

        Hide
        Alok Singh added a comment -

        Attachment temp_dir_fallback.patch has been added with description: Patch to FontCache to use a fallback if the user directory is not writable

        Show
        Alok Singh added a comment - Attachment temp_dir_fallback.patch has been added with description: Patch to FontCache to use a fallback if the user directory is not writable
        Hide
        Jeremias Maerki added a comment -

        Thanks for the patch. I've applied it with modifications:
        http://svn.apache.org/viewvc?rev=743273&view=rev

        The problem was that your code didn't handle the case correctly that the font cache already existed in the user home. It always switched to the temporary directory. I've also had trouble automatically applying the patch. Not sure what was wrong. Had to do it manually.

        Show
        Jeremias Maerki added a comment - Thanks for the patch. I've applied it with modifications: http://svn.apache.org/viewvc?rev=743273&view=rev The problem was that your code didn't handle the case correctly that the font cache already existed in the user home. It always switched to the temporary directory. I've also had trouble automatically applying the patch. Not sure what was wrong. Had to do it manually.
        Hide
        Glenn Adams added a comment -

        batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

        Show
        Glenn Adams added a comment - batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed

          People

          • Assignee:
            fop-dev
            Reporter:
            Alok Singh
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development