From 34c5ece6364e11ba7dea02117b320e7e346abf09 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Wed, 11 Feb 2009 08:41:04 +0000 Subject: [PATCH] Bugzilla #46686: Use temporary directory for the font cache if the user home directory is not write-accessible. Submitted by: Alok Singh 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 --- src/java/org/apache/fop/fonts/FontCache.java | 27 +++++++++++++++----- status.xml | 4 +++ 2 files changed, 25 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); } diff --git a/status.xml b/status.xml index 2e6e4eb11..74393873d 100644 --- a/status.xml +++ b/status.xml @@ -58,6 +58,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Use temporary directory for the font cache if the user home directory is not + write-accessible. + AFP Fonts: Fixed interpretation of metric for fonts with fixed metrics and made sure all repeating groups in FNP (Font Position) are processed. -- 2.39.5