aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge/jnlp/cache/CacheUtil.java
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2012-02-01 18:23:10 +0100
committerJiri Vanek <[email protected]>2012-02-01 18:23:10 +0100
commit8dfc3c1bd0fcaa60a0defd85cd044b954de4ccfb (patch)
tree98c5c0c86bef90c9a5ed16c761c763d6db5c0573 /netx/net/sourceforge/jnlp/cache/CacheUtil.java
parent83a814966b14deb946e6c9fa9b55a75b9e22472d (diff)
fixed LRU cache behaviour in case of failure. Tests added.
Diffstat (limited to 'netx/net/sourceforge/jnlp/cache/CacheUtil.java')
-rw-r--r--netx/net/sourceforge/jnlp/cache/CacheUtil.java39
1 files changed, 35 insertions, 4 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/CacheUtil.java b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
index b88c6e9..320b0f2 100644
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java
+++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java
@@ -144,16 +144,16 @@ public class CacheUtil {
* process is using them can be quite disasterous. Hence why Launcher creates lock files
* and we check for those by calling {@link #okToClearCache()}
*/
- public static void clearCache() {
+ public static boolean clearCache() {
if (!okToClearCache()) {
System.err.println(R("CCannotClearCache"));
- return;
+ return false;
}
File cacheDir = new File(CacheUtil.cacheDir);
if (!(cacheDir.isDirectory())) {
- return;
+ return false;
}
if (JNLPRuntime.isDebug()) {
@@ -165,6 +165,7 @@ public class CacheUtil {
} catch (IOException e) {
throw new RuntimeException(e);
}
+ return true;
}
/**
@@ -322,7 +323,37 @@ public class CacheUtil {
private static File getCacheFileIfExist(File urlPath) {
synchronized (lruHandler) {
File cacheFile = null;
- List<Entry<String, String>> entries = lruHandler.getLRUSortedEntries();
+ int tries = 0;
+ List<Entry<String, String>> entries = null;
+ do {
+ try {
+ tries++;
+ entries = lruHandler.getLRUSortedEntries();
+ } catch (LruCacheException ex) {
+ if (tries == 1) {
+ ex.printStackTrace();
+ System.out.println(R("CFakeCache"));
+ lruHandler.clearLRUSortedEntries();
+ lruHandler.store();
+ System.out.println(R("CFakedCache"));
+ } else if (tries == 2) {
+ ex.printStackTrace();
+ System.out.println(R("CStillCorupted"));
+ boolean clearingresult = CacheUtil.clearCache();
+ if (!clearingresult) {
+ throw new InternalError(R("CCleaningUnsuccessful"));
+ }
+ System.out.println(R("CClearedReloading"));
+ lruHandler.clearLRUSortedEntries();
+ lruHandler.store();
+ System.out.println(R("CReloadRestarting"));
+
+ } else {
+ throw new InternalError(R("CStillBroken"));
+ }
+
+ }
+ } while (entries == null);
// Start searching from the most recent to least recent.
for (Entry<String, String> e : entries) {
final String key = e.getKey();