From 552608744d5f4eb5559fa10ad36ff9ac5e6f1529 Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Wed, 25 May 2011 16:54:25 +0000 Subject: [PATCH] * CPUID: If the 64 bit extract worked but the load failed, try 32 bit --- .../freenet/support/CPUInformation/CPUID.java | 43 +++++++++++++------ .../src/net/i2p/router/RouterVersion.java | 2 +- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java index 3d9c8fe24..30d94a28e 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUID.java +++ b/core/java/src/freenet/support/CPUInformation/CPUID.java @@ -612,24 +612,37 @@ public class CPUID { * */ private static final boolean loadFromResource() { - URL resource = null; // try 64 bit first, if getResourceName64() returns non-null String resourceName = getResourceName64(); - if (resourceName != null) - resource = CPUID.class.getClassLoader().getResource(resourceName); - - if (resource == null) { - // now try 32 bit - resourceName = getResourceName(); - resource = CPUID.class.getClassLoader().getResource(resourceName); + if (resourceName != null) { + boolean success = extractLoadAndCopy(resourceName); + if (success) + return true; } + + // now try 32 bit + resourceName = getResourceName(); + boolean success = extractLoadAndCopy(resourceName); + if (success) + return true; - if (resource == null) { - if (_doLog) - System.err.println("WARNING: Resource name [" + resourceName + "] was not found"); - return false; - } + if (_doLog) + System.err.println("WARNING: Resource name [" + resourceName + "] was not found"); + return false; + } + /** + * Extract a single resource, copy it to a temp location in the file system, + * and attempt to load it. If the load succeeds, copy it to the installation + * directory. Return value reflects only load success - copy will fail silently. + * + * @return true if it was loaded successfully, else false. + * @since 0.8.7 + */ + private static final boolean extractLoadAndCopy(String resourceName) { + URL resource = CPUID.class.getClassLoader().getResource(resourceName); + if (resource == null) + return false; File outFile = null; FileOutputStream fos = null; String filename = libPrefix + "jcpuid" + libSuffix; @@ -652,12 +665,16 @@ public class CPUID { + " was not a valid library for this platform"); ule.printStackTrace(); } + if (outFile != null) + outFile.delete(); return false; } catch (IOException ioe) { if (_doLog) { System.err.println("ERROR: Problem writing out the temporary native library data"); ioe.printStackTrace(); } + if (outFile != null) + outFile.delete(); return false; } finally { if (fos != null) { diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index c10128fe6..fecba78d6 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 6; + public final static long BUILD = 7; /** for example "-test" */ public final static String EXTRA = ""; -- GitLab