From bf4d413ea185e857de534913c556f00435ba9f21 Mon Sep 17 00:00:00 2001
From: Sven Gothel
* On standard Java the {@code temp-root} folder is specified by
- File tmpBaseDir;
+ File tmpBaseDir = null;
if(null != testDir(tmpRoot, true, executable)) { // check tmpRoot first
- tmpBaseDir = testDir(new File(tmpRoot, tmpSubDirPrefix), true, executable);
for(int i = 0; null == tmpBaseDir && i<=9999; i++) {
final String tmpDirSuffix = String.format("_%04d", i); // 4 digits for iteration
tmpBaseDir = testDir(new File(tmpRoot, tmpSubDirPrefix+tmpDirSuffix), true, executable);
@@ -797,9 +796,8 @@ public class IOUtil {
private static File getSubTempDir(File tmpRoot, String tmpSubDirPrefix, boolean executable)
throws SecurityException
{
- File tmpBaseDir;
+ File tmpBaseDir = null;
if(null != testDirImpl(tmpRoot, true /* create */, executable)) { // check tmpRoot first
- tmpBaseDir = testDirImpl(new File(tmpRoot, tmpSubDirPrefix), true /* create */, executable);
for(int i = 0; null == tmpBaseDir && i<=9999; i++) {
final String tmpDirSuffix = String.format("_%04d", i); // 4 digits for iteration
tmpBaseDir = testDirImpl(new File(tmpRoot, tmpSubDirPrefix+tmpDirSuffix), true /* create */, executable);
@@ -897,7 +895,7 @@ public class IOUtil {
/**
* Returns a platform independent writable directory for temporary files
* consisting of the platform's {@code temp-root} + {@link #tmpSubDir},
- * e.g. {@code /tmp/jogamp/}.
+ * e.g. {@code /tmp/jogamp_0000/}.
*
java.io.tempdir
.
*
* In case {@code temp-root} is the users home folder, - * a dot is being prepended to {@link #tmpSubDir}, i.e.: {@code /home/user/.jogamp/}. + * a dot is being prepended to {@link #tmpSubDir}, i.e.: {@code /home/user/.jogamp_0000/}. *
* @param executable true if the user intents to launch executables from the temporary directory, otherwise false. * @param acc The security {@link AccessControlContext} to access properties, environment vars, create directories and test executability diff --git a/src/java/com/jogamp/common/util/cache/TempFileCache.java b/src/java/com/jogamp/common/util/cache/TempFileCache.java index 7eebbd0..755ed7b 100644 --- a/src/java/com/jogamp/common/util/cache/TempFileCache.java +++ b/src/java/com/jogamp/common/util/cache/TempFileCache.java @@ -132,17 +132,19 @@ public class TempFileCache { * system property. * * a. If set, then some other thread in a different ClassLoader has - * already created the tmprootdir, so we just need to + * already created the tmpRootDir, so we just need to * use it. The remaining steps are skipped. + * However, we check the existence of the tmpRootDir + * and if non existent, we assume a new launch and continue. * * b. If not set, then we are the first thread in this JVM to run, - * and we need to create the the tmprootdir. + * and we need to create the the tmpRootDir. * - * 3. Create the tmprootdir, along with the appropriate locks. + * 3. Create the tmpRootDir, along with the appropriate locks. * Note that we perform the operations in the following order, - * prior to creating tmprootdir itself, to work around the fact that + * prior to creating tmpRootDir itself, to work around the fact that * the file creation and file lock steps are not atomic, and we need - * to ensure that a newly-created tmprootdir isn't reaped by a + * to ensure that a newly-created tmpRootDir isn't reaped by a * concurrently running JVM. * * create jlnNNNN.tmp using File.createTempFile() @@ -170,6 +172,36 @@ public class TempFileCache { private static void initTmpRoot() throws IOException { tmpRootPropValue = System.getProperty(tmpRootPropName); + if (tmpRootPropValue != null) { + // Make sure that the property is not set to an illegal value + if (tmpRootPropValue.indexOf('/') >= 0 || + tmpRootPropValue.indexOf(File.separatorChar) >= 0) { + throw new IOException("Illegal value of: " + tmpRootPropName); + } + + // Set tmpRootDir = ${tmpbase}/${jnlp.applet.launcher.tmproot} + if (DEBUG) { + System.err.println("TempFileCache: Trying existing value of: " + + tmpRootPropName + "=" + tmpRootPropValue); + } + tmpRootDir = new File(tmpBaseDir, tmpRootPropValue); + if (DEBUG) { + System.err.println("TempFileCache: Trying tmpRootDir = " + tmpRootDir.getAbsolutePath()); + } + if (tmpRootDir.isDirectory()) { + if (!tmpRootDir.canWrite()) { + throw new IOException("Temp root directory is not writable: " + tmpRootDir.getAbsolutePath()); + } + } else { + // It is possible to move to a new GlueGen version within the same JVM + // In case tmpBaseDir has changed, we should assume a new tmpRootDir. + System.err.println("TempFileCache: None existing tmpRootDir = " + tmpRootDir.getAbsolutePath()+", assuming new path due to update"); + tmpRootPropValue = null; + tmpRootDir = null; + System.clearProperty(tmpRootPropName); + } + } + if (tmpRootPropValue == null) { // Create ${tmpbase}/jlnNNNN.tmp then lock the file File tmpFile = File.createTempFile("jln", ".tmp", tmpBaseDir); @@ -241,28 +273,6 @@ public class TempFileCache { }; reaperThread.setName("TempFileCache-Reaper"); reaperThread.start(); - } else { - // Make sure that the property is not set to an illegal value - if (tmpRootPropValue.indexOf('/') >= 0 || - tmpRootPropValue.indexOf(File.separatorChar) >= 0) { - throw new IOException("Illegal value of: " + tmpRootPropName); - } - - // Set tmpRootDir = ${tmpbase}/${jnlp.applet.launcher.tmproot} - if (DEBUG) { - System.err.println("TempFileCache: Using existing value of: " + - tmpRootPropName + "=" + tmpRootPropValue); - } - tmpRootDir = new File(tmpBaseDir, tmpRootPropValue); - if (DEBUG) { - System.err.println("TempFileCache: tmpRootDir = " + tmpRootDir.getAbsolutePath()); - } - if (!tmpRootDir.isDirectory()) { - throw new IOException("Temp root directory does not exist: " + tmpRootDir.getAbsolutePath()); - } - if (!tmpRootDir.canWrite()) { - throw new IOException("Temp root directory is not writable: " + tmpRootDir.getAbsolutePath()); - } } } diff --git a/src/java/com/jogamp/common/util/cache/TempJarCache.java b/src/java/com/jogamp/common/util/cache/TempJarCache.java index 8aaab94..e4a77fe 100644 --- a/src/java/com/jogamp/common/util/cache/TempJarCache.java +++ b/src/java/com/jogamp/common/util/cache/TempJarCache.java @@ -411,6 +411,11 @@ public class TempJarCache { // In case one tries to run uncertified JARs, the wrapping applet/JNLP // SecurityManager will kick in and throw a SecurityException. JarUtil.validateCertificates(rootCerts, jarFile); - } + if(DEBUG) { + System.err.println("TempJarCache: validateCertificates: OK - Matching rootCerts in given class "+certClass.getName()+", nativeJar "+jarFile.getName()); + } + } else if(DEBUG) { + System.err.println("TempJarCache: validateCertificates: OK - No rootCerts in given class "+certClass.getName()+", nativeJar "+jarFile.getName()); + } } } diff --git a/src/java/jogamp/android/launcher/LauncherTempFileCache.java b/src/java/jogamp/android/launcher/LauncherTempFileCache.java index 7e566c9..c7b9ad0 100644 --- a/src/java/jogamp/android/launcher/LauncherTempFileCache.java +++ b/src/java/jogamp/android/launcher/LauncherTempFileCache.java @@ -101,6 +101,8 @@ public class LauncherTempFileCache { * a. If set, then some other thread in a different ClassLoader has * already created the tmprootdir, so we just need to * use it. The remaining steps are skipped. + * However, we check the existence of the tmpRootDir + * and if non existent, we assume a new launch and continue. * * b. If not set, then we are the first thread in this JVM to run, * and we need to create the the tmprootdir. @@ -148,6 +150,36 @@ public class LauncherTempFileCache { } tmpRootPropValue = System.getProperty(tmpRootPropName); + if (tmpRootPropValue != null) { + // Make sure that the property is not set to an illegal value + if (tmpRootPropValue.indexOf('/') >= 0 || + tmpRootPropValue.indexOf(File.separatorChar) >= 0) { + throw new IOException("Illegal value of: " + tmpRootPropName); + } + + // Set tmpRootDir = ${tmpbase}/${jnlp.applet.launcher.tmproot} + if (DEBUG) { + System.err.println("TempFileCache: Trying existing value of: " + + tmpRootPropName + "=" + tmpRootPropValue); + } + tmpRootDir = new File(tmpBaseDir, tmpRootPropValue); + if (DEBUG) { + System.err.println("TempFileCache: Trying tmpRootDir = " + tmpRootDir.getAbsolutePath()); + } + if (tmpRootDir.isDirectory()) { + if (!tmpRootDir.canWrite()) { + throw new IOException("Temp root directory is not writable: " + tmpRootDir.getAbsolutePath()); + } + } else { + // It is possible to move to a new GlueGen version within the same JVM + // In case tmpBaseDir has changed, we should assume a new tmpRootDir. + System.err.println("TempFileCache: None existing tmpRootDir = " + tmpRootDir.getAbsolutePath()+", assuming new path due to update"); + tmpRootPropValue = null; + tmpRootDir = null; + System.clearProperty(tmpRootPropName); + } + } + if (tmpRootPropValue == null) { // Create the tmpbase directory if it doesn't already exist tmpBaseDir.mkdirs(); @@ -225,25 +257,6 @@ public class LauncherTempFileCache { }; reaperThread.setName("TempFileCache-Reaper"); reaperThread.start(); - } else { - // Make sure that the property is not set to an illegal value - if (tmpRootPropValue.indexOf('/') >= 0 || - tmpRootPropValue.indexOf(File.separatorChar) >= 0) { - throw new IOException("Illegal value of: " + tmpRootPropName); - } - - // Set tmpRootDir = ${tmpbase}/${jnlp.applet.launcher.tmproot} - if (DEBUG) { - System.err.println("TempFileCache: Using existing value of: " + - tmpRootPropName + "=" + tmpRootPropValue); - } - tmpRootDir = new File(tmpBaseDir, tmpRootPropValue); - if (DEBUG) { - System.err.println("TempFileCache: tmpRootDir = " + tmpRootDir.getAbsolutePath()); - } - if (!tmpRootDir.isDirectory()) { - throw new IOException("Cannot access " + tmpRootDir); - } } } if (DEBUG) { -- cgit v1.2.3