From 7da232b5b92cf679bd424bcb14aac5f8da9624be Mon Sep 17 00:00:00 2001 From: borg-0300 Date: Tue, 3 Jan 2006 11:02:02 +0000 Subject: [PATCH] HTCache Reset if necessary git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1280 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/plasma/plasmaHTCache.java | 44 +++++++++++----------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/source/de/anomic/plasma/plasmaHTCache.java b/source/de/anomic/plasma/plasmaHTCache.java index 889e11e2b..78e7b0c85 100644 --- a/source/de/anomic/plasma/plasmaHTCache.java +++ b/source/de/anomic/plasma/plasmaHTCache.java @@ -101,6 +101,25 @@ public final class plasmaHTCache { this.cachePath = htCachePath; this.maxCacheSize = maxCacheSize; + // reset old HTCache ? + final String[] list = cachePath.list(); + if (list != null) { + 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")) { + deleteOldHTCache(cachePath); + break; + } + } + } + } + // set/make cache path if (!htCachePath.exists()) { htCachePath.mkdirs(); @@ -110,23 +129,7 @@ public final class plasmaHTCache { 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 { @@ -152,7 +155,7 @@ public final class plasmaHTCache { serverInstantThread.oneTimeJob(this, "cacheScan", this.log, 120000); } - private void deleteOldCache(File directory) { + private void deleteOldHTCache(File directory) { String[] list = directory.list(); File object; for (int i = list.length - 1; i >= 0 ; i--) { @@ -160,7 +163,7 @@ public final class plasmaHTCache { if (object.isFile()) { object.delete(); } else { - deleteOldCache(object); + deleteOldHTCache(object); } } directory.delete(); @@ -269,9 +272,8 @@ public final class plasmaHTCache { private boolean deleteFile(File obj) { if (obj.exists() && !filesInUse.contains(obj)) { - long size = obj.length(); if (obj.delete()) { - this.currCacheSize -= size; + this.currCacheSize -= obj.length(); return true; } }