Skip to content

Commit

Permalink
HTCache Reset if necessary
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@1280 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
borg-0300 committed Jan 3, 2006
1 parent c7a4bf7 commit 7da232b
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions source/de/anomic/plasma/plasmaHTCache.java
Expand Up @@ -101,6 +101,25 @@ public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb) {
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();
Expand All @@ -110,23 +129,7 @@ public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb) {
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 {
Expand All @@ -152,15 +155,15 @@ public plasmaHTCache(File htCachePath, long maxCacheSize, int bufferkb) {
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--) {
object = new File(directory, list[i]);
if (object.isFile()) {
object.delete();
} else {
deleteOldCache(object);
deleteOldHTCache(object);
}
}
directory.delete();
Expand Down Expand Up @@ -269,9 +272,8 @@ private boolean deleteURLfromCache (URL url, String msg) {

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;
}
}
Expand Down

0 comments on commit 7da232b

Please sign in to comment.