diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-02-11 08:41:04 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-02-11 08:41:04 +0000 |
commit | 34c5ece6364e11ba7dea02117b320e7e346abf09 (patch) | |
tree | 085b7b2a9275a0db65f9cc2a665fda672be2581d /src/java/org/apache/fop | |
parent | 8e5a75b2b9b24dcd6c52f5ec3d6081e2b782ac44 (diff) | |
download | xmlgraphics-fop-34c5ece6364e11ba7dea02117b320e7e346abf09.tar.gz xmlgraphics-fop-34c5ece6364e11ba7dea02117b320e7e346abf09.zip |
Bugzilla #46686:
Use temporary directory for the font cache if the user home directory is not write-accessible.
Submitted by: Alok Singh <alok.at.jivesoftware.com>
Modifications to patch by jeremias:
- Bugfix: original code switched to temporary directory if the .fop directory already existed in user home.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@743273 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r-- | src/java/org/apache/fop/fonts/FontCache.java | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/java/org/apache/fop/fonts/FontCache.java b/src/java/org/apache/fop/fonts/FontCache.java index fceeacb7b..9d5eff010 100644 --- a/src/java/org/apache/fop/fonts/FontCache.java +++ b/src/java/org/apache/fop/fonts/FontCache.java @@ -81,11 +81,18 @@ public final class FontCache implements Serializable { } private static File getUserHome() { - String s = System.getProperty("user.home"); - if (s != null) { - File userDir = new File(s); - if (userDir.exists()) { - return userDir; + return toDirectory(System.getProperty("user.home")); + } + + private static File getTempDirectory() { + return toDirectory(System.getProperty("java.io.tmpdir")); + } + + private static File toDirectory(String path) { + if (path != null) { + File dir = new File(path); + if (dir.exists()) { + return dir; } } return null; @@ -101,7 +108,15 @@ public final class FontCache implements Serializable { if (userHome != null) { File fopUserDir = new File(userHome, FOP_USER_DIR); if (forWriting) { - fopUserDir.mkdir(); + boolean writable = fopUserDir.canWrite(); + if (!fopUserDir.exists()) { + writable = fopUserDir.mkdir(); + } + if (!writable) { + userHome = getTempDirectory(); + fopUserDir = new File(userHome, FOP_USER_DIR); + fopUserDir.mkdir(); + } } return new File(fopUserDir, DEFAULT_CACHE_FILENAME); } |