Author: dblevins
Date: Thu Jun 24 09:11:16 2010
New Revision: 957463
URL: http://svn.apache.org/viewvc?rev=957463&view=rev
Log:
Patch from Andy Gumbrecht, OPENEJB-1285: UrlCache fails to recreate temp
directory
Thanks, Andy!
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java?rev=957463&r1=957462&r2=957463&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
Thu Jun 24 09:11:16 2010
@@ -40,9 +40,11 @@ import org.apache.openejb.loader.FileUti
import org.apache.openejb.loader.SystemInstance;
public class UrlCache {
+
private static final Logger logger =
Logger.getInstance(LogCategory.OPENEJB, UrlCache.class);
public static final boolean antiJarLocking;
public static final File cacheDir;
+
static {
String value = null;
for (Map.Entry<Object, Object> entry :
System.getProperties().entrySet()) {
@@ -75,9 +77,7 @@ public class UrlCache {
cacheDir = null;
}
}
-
-
- private final Map<String, Map<URL, File>> cache = new TreeMap<String,
Map<URL,File>>();
+ private final Map<String, Map<URL, File>> cache = new TreeMap<String,
Map<URL, File>>();
public synchronized URL[] cacheUrls(String appId, URL[] urls) {
if (!antiJarLocking) {
@@ -288,34 +288,48 @@ public class UrlCache {
try {
FileUtils openejbBase = SystemInstance.get().getBase();
- File cacheDir = null;
+ File dir = null;
// if we are not embedded, cache (temp) dir is under base dir
if (openejbBase.getDirectory("conf").exists()) {
try {
- cacheDir = openejbBase.getDirectory("temp");
+ dir = openejbBase.getDirectory("temp");
} catch (IOException e) {
+ //Ignore
}
}
// if we are embedded, tmp dir is in the system tmp dir
- if (cacheDir == null) {
- cacheDir = File.createTempFile("OpenEJB-temp-", "");
+ if (dir == null) {
+ dir = File.createTempFile("OpenEJB-temp-", "");
}
- // if the cache dir already exists, clear it out
- if (cacheDir.exists()) {
- deleteDir(cacheDir);
+ // If the cache dir already exists then empty its contents
+ if (dir.exists()) {
+ final File[] files = dir.listFiles();
+ if (null != files) {
+ for (final File f : files) {
+ deleteDir(f);
+ }
+ }
+ } else {
+ dir = createCacheDir(new File(dir.getAbsolutePath()));
}
- // create the cache dir if it no longer exists
- cacheDir.mkdirs();
+ return dir;
- return cacheDir;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
+ private static File createCacheDir(File dir) throws IOException {
+ if (!dir.mkdirs() && !dir.isDirectory()) {
+ throw new IOException("Unable to create cache temp directory: " +
dir);
+ }
+
+ return dir;
+ }
+
/**
* Delete the specified directory, including all of its contents and
* subdirectories recursively.
@@ -323,7 +337,9 @@ public class UrlCache {
* @param dir File object representing the directory to be deleted
*/
public static void deleteDir(File dir) {
- if (dir == null) return;
+ if (dir == null) {
+ return;
+ }
File[] fileNames = dir.listFiles();
if (fileNames != null) {