From c652527620855df70b9b28e40e7d037b40c74d27 Mon Sep 17 00:00:00 2001 From: borg-0300 Date: Mon, 2 Jan 2006 22:24:19 +0000 Subject: [PATCH] YaCy removes now the old HTCACHE data git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1277 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/plasma/plasmaHTCache.java | 37 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.java index b48a6b5e9..94984ec1d 100644 --- a/source/de/anomic/plasma/plasmaHTCache.java +++ b/source/de/anomic/plasma/plasmaHTCache.java @@ -102,15 +102,31 @@ public final class plasmaHTCache { this.maxCacheSize = maxCacheSize; // set/make cache path - if (!(htCachePath.exists())) { + if (!htCachePath.exists()) { htCachePath.mkdirs(); } - if (!(htCachePath.isDirectory())) { + if (!htCachePath.isDirectory()) { // if the cache does not exists or is a file and not a directory, panic this.log.logSevere("the cache path " + htCachePath.toString() + " is not a directory or does not exists and cannot be created"); System.exit(0); } + // delete old Cache + final String[] list = cachePath.list(); + File object; + for (int i = list.length - 1; i >= 0 ; i--) { + object = new File(cachePath, list[i]); + if (object.isDirectory()) { + if (!object.getName().equals("http") && + !object.getName().equals("yacy") && + !object.getName().equals("https") && + !object.getName().equals("ftp") && + !object.getName().equals("anon")) { + deleteOldCache(object); + } + } + } + // open the response header database File dbfile = new File(this.cachePath, "responseHeader.db"); try { @@ -136,6 +152,21 @@ public final class plasmaHTCache { serverInstantThread.oneTimeJob(this, "cacheScan", this.log, 120000); } + private void deleteOldCache(File directory) { + String[] list = directory.list(); + int size = list.length - 1; + File object; + for (int i = size; i >= 0 ; i--) { + object = new File(directory, list[i]); + if (object.isFile()) { + object.delete(); + } else { + deleteOldCache(object); + } + } + directory.delete(); + } + public int size() { synchronized (this.cacheStack) { return this.cacheStack.size(); @@ -186,7 +217,7 @@ public final class plasmaHTCache { */ public long getFreeSize() { return (this.currCacheSize >= this.maxCacheSize) ? 0 : this.maxCacheSize - this.currCacheSize; - } + } public boolean writeFile(URL url, byte[] array) { if (array == null) return false;