changeset 11117:fa5618c135c7 12+3

8214397: Provide fallback if user home is not writable for native libs Reviewed-by: kcr
author jvos
date Thu, 29 Nov 2018 21:09:09 +0100
parents 6859462e6792
children 55aac90d1e86
files modules/javafx.graphics/src/main/java/com/sun/glass/utils/NativeLibLoader.java
diffstat 1 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.graphics/src/main/java/com/sun/glass/utils/NativeLibLoader.java	Tue Nov 20 15:29:42 2018 +0100
+++ b/modules/javafx.graphics/src/main/java/com/sun/glass/utils/NativeLibLoader.java	Thu Nov 29 21:09:09 2018 +0100
@@ -222,15 +222,39 @@
 
     private static String cacheLibrary(InputStream is, String name, Class caller) throws IOException {
         String jfxVersion = System.getProperty("javafx.version", "versionless");
-        String userCache = System.getProperty("user.home") + "/.openjfx/cache/" + jfxVersion;
+        String userCache = System.getProperty("javafx.cachedir", "");
+        if (userCache.isEmpty()) {
+            userCache = System.getProperty("user.home") + "/.openjfx/cache/" + jfxVersion;
+        }
         File cacheDir = new File(userCache);
+        boolean cacheDirOk = true;
         if (cacheDir.exists()) {
             if (!cacheDir.isDirectory()) {
-                throw new IOException ("Cache exists but is not a directory: "+cacheDir);
+                System.err.println("Cache exists but is not a directory: "+cacheDir);
+                cacheDirOk = false;
             }
         } else {
             if (!cacheDir.mkdirs()) {
-                throw new IOException ("Can not create cache at "+cacheDir);
+                System.err.println("Can not create cache at "+cacheDir);
+                cacheDirOk = false;
+            }
+        }
+        if (!cacheDir.canRead()) {
+            // on some systems, directories in user.home can be written but not read.
+            cacheDirOk = false;
+        }
+        if (!cacheDirOk) {
+            String username = System.getProperty("user.name", "anonymous");
+            String tmpCache = System.getProperty("java.io.tmpdir") + "/.openjfx_" + username + "/cache/" + jfxVersion;
+            cacheDir = new File(tmpCache);
+            if (cacheDir.exists()) {
+                if (!cacheDir.isDirectory()) {
+                    throw new IOException("Cache exists but is not a directory: "+cacheDir);
+                }
+            } else {
+                if (!cacheDir.mkdirs()) {
+                    throw new IOException("Can not create cache at "+cacheDir);
+                }
             }
         }
         // we have a cache directory. Add the file here