Skip to content

Commit b174117

Browse files
author
andreas
committed
Fix for issue jMonkeyEngine#2302 - NativeLibraryLoader fails due to no write permissions
Extract native library to a folder directly beneath the user temp folder. Do not use an intermediate /jme subfolder. Check the result of the call to mkdir. Use UserCache if creation failed. Check if the extraction folder is actually writable. If not use the UserCache. Updated log message: since a previous change we no longer extract to the working directory.
1 parent e2e9a94 commit b174117

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,15 @@ public static File getExtractionFolder() {
198198
setExtractionFolderToUserCache();
199199
} else {
200200
try {
201-
File jmeTempDir = new File(userTempDir, "jme3");
202-
if (!jmeTempDir.exists()) {
203-
jmeTempDir.mkdir();
204-
}
205-
extractionFolder = new File(jmeTempDir, "natives_" + Integer.toHexString(computeNativesHash()));
201+
extractionFolder = new File(userTempDir, "jme3_natives_" + Integer.toHexString(computeNativesHash()));
206202

207203
if (!extractionFolder.exists()) {
208-
extractionFolder.mkdir();
204+
if(!extractionFolder.mkdir()) {
205+
throw new IOException("Failed to create folder "+extractionFolder);
206+
}
207+
}
208+
if(!extractionFolder.canWrite()) {
209+
setExtractionFolderToUserCache();
209210
}
210211
} catch (Exception e) {
211212
setExtractionFolderToUserCache();
@@ -268,7 +269,7 @@ private static void setExtractionFolderToUserCache() {
268269
extractionFolder.mkdir();
269270
}
270271

271-
logger.log(Level.WARNING, "Working directory is not writable. "
272+
logger.log(Level.WARNING, "Temp directory is not writable. "
272273
+ "Natives will be extracted to:\n{0}",
273274
extractionFolder);
274275
}

0 commit comments

Comments
 (0)