Skip to content

Commit

Permalink
8214397: Provide fallback if user home is not writable for native libs
Browse files Browse the repository at this point in the history
Reviewed-by: kcr
  • Loading branch information
jvos committed Nov 29, 2018
1 parent 503a1d0 commit 02fbf21
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,39 @@ private static boolean installLibraryFromResource(String libraryName, List<Strin

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
Expand Down

0 comments on commit 02fbf21

Please sign in to comment.