Mercurial > hg > release > icedtea-web-1.6
changeset 1169:8cae163ee8bd
Fixed broken CacheUtil.
* netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java: removed misleading one parameter constructor.
* netx/net/sourceforge/jnlp/cache/CacheUtil.java: adapted to new CacheLRUWrapper
* tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java: adapted to new constructor.
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Wed, 04 Mar 2015 17:24:29 +0100 |
parents | a89fc59ab516 |
children | aaea16216604 |
files | ChangeLog netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java netx/net/sourceforge/jnlp/cache/CacheUtil.java tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java |
diffstat | 4 files changed, 28 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Tue Mar 03 17:04:24 2015 +0100 +++ b/ChangeLog Wed Mar 04 17:24:29 2015 +0100 @@ -1,3 +1,12 @@ +2015-03-04 Jiri Vanek <jvanek@redhat.com> + + Fixed broken CacheUtil. + * netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java: removed misleading one + parameter constructor. + * netx/net/sourceforge/jnlp/cache/CacheUtil.java: adapted to new CacheLRUWrapper + * tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java: adapted + to new constructor. + 2015-03-03 Jiri Vanek <jvanek@redhat.com> Changing enum CacheLRUWrapper singleton to instantiatible one. recently_used
--- a/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Tue Mar 03 17:04:24 2015 +0100 +++ b/netx/net/sourceforge/jnlp/cache/CacheLRUWrapper.java Wed Mar 04 17:24:29 2015 +0100 @@ -69,20 +69,12 @@ private final PropertiesFile recentlyUsedPropertiesFile; private final File cacheDir; - private final File recentlyUsedFile; - + public CacheLRUWrapper() { - this(PathsAndFiles.RECENTLY_USED_FILE.getFile()); + this(PathsAndFiles.RECENTLY_USED_FILE.getFile(), PathsAndFiles.CACHE_DIR.getFile()); } - /** - * testing constructor - * @param recentlyUsed file to be used as recently_used file. its parent will be used as cache dir - */ - public CacheLRUWrapper(final File recentlyUsed) { - this(recentlyUsed, recentlyUsed.getParentFile()); - } - + /** * testing constructor * @param recentlyUsed file to be used as recently_used file @@ -90,7 +82,6 @@ */ public CacheLRUWrapper(final File recentlyUsed, final File cacheDir) { recentlyUsedPropertiesFile = new PropertiesFile(recentlyUsed); - recentlyUsedFile = recentlyUsed; this.cacheDir = cacheDir; if (!recentlyUsed.exists()) { try { @@ -129,7 +120,7 @@ * @return the recentlyUsedFile */ public File getRecentlyUsedFile() { - return recentlyUsedFile; + return recentlyUsedPropertiesFile.getStoreFile(); } private static class CacheLRUWrapperHolder{ @@ -179,7 +170,7 @@ // 2. check path format - does the path look correct? if (path != null) { - if (!path.contains(cacheDir.getAbsolutePath())) { + if (!path.contains(getCacheDir().getAbsolutePath())) { it.remove(); modified = true; }
--- a/netx/net/sourceforge/jnlp/cache/CacheUtil.java Tue Mar 03 17:04:24 2015 +0100 +++ b/netx/net/sourceforge/jnlp/cache/CacheUtil.java Wed Mar 04 17:24:29 2015 +0100 @@ -58,9 +58,7 @@ */ public class CacheUtil { - private static final String setCacheDir = JNLPRuntime.getConfiguration().getProperty(DeploymentConfiguration.KEY_USER_CACHE_DIR); - private static final String cacheDir = new File(setCacheDir != null ? setCacheDir : System.getProperty("java.io.tmpdir")).getPath(); // Do this with file to standardize it. - private static final CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); + /** * Caches a resource and returns a URL for it in the cache; @@ -144,8 +142,9 @@ OutputController.getLogger().log(OutputController.Level.ERROR_ALL, R("CCannotClearCache")); return false; } - - File cacheDir = new File(CacheUtil.cacheDir); + + CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); + File cacheDir = lruHandler.getCacheDir(); if (!(cacheDir.isDirectory())) { return false; } @@ -292,6 +291,7 @@ throw new IllegalArgumentException(R("CNotCacheable", source)); File cacheFile = null; + CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); synchronized (lruHandler) { try { lruHandler.lock(); @@ -318,6 +318,7 @@ * @return File if we have searched before, {@code null} otherwise. */ private static File getCacheFileIfExist(File urlPath) { + CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); synchronized (lruHandler) { File cacheFile = null; List<Entry<String, String>> entries = lruHandler.getLRUSortedEntries(); @@ -340,7 +341,7 @@ * Get the path to file minus the cache directory and indexed folder. */ private static String pathToURLPath(String path) { - int len = cacheDir.length(); + int len = CacheLRUWrapper.getInstance().getCacheDir().getAbsolutePath().length(); int index = path.indexOf(File.separatorChar, len + 1); return path.substring(index); } @@ -352,6 +353,7 @@ public static String getCacheParentDirectory(String filePath) { String path = filePath; String tempPath = ""; + String cacheDir = CacheLRUWrapper.getInstance().getCacheDir().getAbsolutePath(); while(path.startsWith(cacheDir) && !path.equals(cacheDir)){ tempPath = new File(path).getParent(); @@ -374,13 +376,14 @@ * @return the file location in the cache. */ public static File makeNewCacheFile(URL source, Version version) { + CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); synchronized (lruHandler) { File cacheFile = null; try { lruHandler.lock(); lruHandler.load(); for (long i = 0; i < Long.MAX_VALUE; i++) { - String path = cacheDir + File.separator + i; + String path = lruHandler.getCacheDir().getAbsolutePath() + File.separator + i; File cDir = new File(path); if (!cDir.exists()) { // We can use this directory. @@ -552,6 +555,7 @@ * This will remove all old cache items. */ public static void cleanCache() { + CacheLRUWrapper lruHandler = CacheLRUWrapper.getInstance(); if (okToClearCache()) { // First we want to figure out which stuff we need to delete. HashSet<String> keep = new HashSet<>(); @@ -586,8 +590,8 @@ * rStr first becomes: /0/http/www.example.com/subdir/a.jar * then rstr becomes: /home/user1/.icedtea/cache/0 */ - String rStr = file.getPath().substring(cacheDir.length()); - rStr = cacheDir + rStr.substring(0, rStr.indexOf(File.separatorChar, 1)); + String rStr = file.getPath().substring(lruHandler.getCacheDir().getAbsolutePath().length()); + rStr =lruHandler.getCacheDir().getAbsolutePath() + rStr.substring(0, rStr.indexOf(File.separatorChar, 1)); long len = file.length(); if (keep.contains(file.getPath().substring(rStr.length()))) {
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java Tue Mar 03 17:04:24 2015 +0100 +++ b/tests/netx/unit/net/sourceforge/jnlp/cache/CacheLRUWrapperTest.java Wed Mar 04 17:24:29 2015 +0100 @@ -75,7 +75,7 @@ } } - private static final CacheLRUWrapper clw = new CacheLRUWrapper(new File(tmpCache, cacheIndexFileName)); + private static final CacheLRUWrapper clw = new CacheLRUWrapper(new File(tmpCache, cacheIndexFileName), tmpCache); private final int noEntriesCacheFile = 1000;