- fixed NPE in Blacklist Cleaner during deletion of more than one double entries

- don't display responseHeader1.db in CacheAdmin_p anymore

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3814 6c8d7289-2bf4-0310-a012-ef5d649a1542
This commit is contained in:
karlchenofhell 2007-06-06 23:36:38 +00:00
parent 3f49cd516b
commit 9d6605a83c
3 changed files with 37 additions and 19 deletions

View File

@ -53,6 +53,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -119,10 +120,10 @@ public class BlacklistCleaner_p {
if (post.containsKey("delete")) {
prop.put(RESULTS + "modified", 1);
prop.put(RESULTS + "modified_delCount", removeEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true)));
prop.put(RESULTS + "modified_delCount", removeEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true, true)));
} else if (post.containsKey("alter")) {
prop.put(RESULTS + "modified", 2);
prop.put(RESULTS + "modified_alterCount", alterEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true), getByPrefix(post, "entry", false)));
prop.put(RESULTS + "modified_alterCount", alterEntries(blacklistToUse, supportedBlacklistTypes, getByPrefix(post, "select", true, false), getByPrefix(post, "entry", false, false)));
}
// list illegal entries
@ -171,8 +172,13 @@ public class BlacklistCleaner_p {
}
}
private static String[] getByPrefix(serverObjects post, String prefix, boolean useKeys) {
ArrayList r = new ArrayList();
private static String[] getByPrefix(serverObjects post, String prefix, boolean useKeys, boolean useHashSet) {
Collection r;
if (useHashSet) {
r = new HashSet();
} else {
r = new ArrayList();
}
Iterator it;
String s;
if (useKeys) {
@ -280,9 +286,12 @@ public class BlacklistCleaner_p {
// remove the entry from the running blacklist engine
for (int blTypes=0; blTypes < supportedBlacklistTypes.length; blTypes++) {
if (listManager.ListInListslist(supportedBlacklistTypes[blTypes] + ".BlackLists", blacklistToUse)) {
String host = (s.indexOf("/") == -1) ? s : s.substring(0, s.indexOf("/"));
String path = (s.indexOf("/") == -1) ? ".*" : s.substring(s.indexOf("/") + 1);
try {
plasmaSwitchboard.urlBlacklist.remove(supportedBlacklistTypes[blTypes],
(s.indexOf("/") == -1) ? s : s.substring(0, s.indexOf("/")),
(s.indexOf("/") == -1) ? ".*" : s.substring(s.indexOf("/") + 1));
host,path);
} catch (RuntimeException e) { System.err.println(e.getMessage() + ": " + host + "/" + path); }
}
}
}

View File

@ -51,6 +51,7 @@
*/
import java.io.File;
import java.io.FilenameFilter;
import java.io.Writer;
import java.util.Iterator;
import java.util.Map;
@ -61,6 +62,7 @@ import de.anomic.htmlFilter.htmlFilterImageEntry;
import de.anomic.htmlFilter.htmlFilterWriter;
import de.anomic.http.httpHeader;
import de.anomic.net.URL;
import de.anomic.plasma.plasmaHTCache;
import de.anomic.plasma.plasmaParserDocument;
import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.cache.IResourceInfo;
@ -78,6 +80,15 @@ public class CacheAdmin_p {
private static final int HtmlFile = 0;
private static final int NotCached = 1;
private static final int Image = 2;
public static final class Filter implements FilenameFilter {
private static final String EXCLUDE_NAME = plasmaHTCache.DB_NAME;
private final File EXCLUDE_DIR;
public Filter(File path) { this.EXCLUDE_DIR = path; }
public boolean accept(File dir, String name) {
return !dir.equals(EXCLUDE_DIR) && !name.equals(EXCLUDE_NAME);
}
}
public static serverObjects respond(httpHeader header, serverObjects post, serverSwitch env) {
final plasmaSwitchboard switchboard = (plasmaSwitchboard) env;
@ -107,7 +118,7 @@ public class CacheAdmin_p {
String urlstr = "";
if (action.equals("info") && !file.isDirectory()) { // normal file
if (action.equals("info") && !file.isDirectory() && url != null) { // normal file
prop.put("info", TypeFILE);
// path.append((pathString.length() == 0) ? linkPathString("/", true) : linkPathString(pathString, false));
linkPathString(prop, ((pathString.length() == 0) ? ("/") : (pathString)), true);
@ -187,7 +198,7 @@ public class CacheAdmin_p {
}
// generate sorted dir/file listing
final String[] list = dir.list();
final String[] list = dir.list(new Filter(new File(switchboard.getConfig(plasmaSwitchboard.HTCACHE_PATH, plasmaSwitchboard.HTCACHE_PATH_DEFAULT))));
tree.ensureCapacity((list == null) ? 70 : (list.length + 1) * 256);
linkPathString(prop, ((pathString.length() == 0) ? ("/") : (pathString)), true);
if (list == null) {
@ -196,16 +207,12 @@ public class CacheAdmin_p {
prop.put("info_empty", 0);
final TreeSet dList = new TreeSet();
final TreeSet fList = new TreeSet();
File object;
int size = list.length - 1, i = size;
for (; i >= 0 ; i--) { // Rueckwaerts ist schneller
object = new File(dir, list[i]);
if (!object.getName().equalsIgnoreCase("responseHeader.db")) {
if (object.isDirectory())
dList.add(list[i]);
else
fList.add(list[i]);
}
if (new File(dir, list[i]).isDirectory())
dList.add(list[i]);
else
fList.add(list[i]);
}
Iterator iter = dList.iterator();

View File

@ -93,7 +93,9 @@ import de.anomic.yacy.yacySeed;
import de.anomic.yacy.yacySeedDB;
public final class plasmaHTCache {
public static final String DB_NAME = "responseHeader1.db";
private static final int stackLimit = 150; // if we exceed that limit, we do not check idle
public static final long oneday = 1000 * 60 * 60 * 24; // milliseconds of a day
@ -189,14 +191,14 @@ public final class plasmaHTCache {
private void resetResponseHeaderDB() {
if (this.responseHeaderDB != null) this.responseHeaderDB.close();
File dbfile = new File(this.cachePath, "responseHeader1.db");
File dbfile = new File(this.cachePath, DB_NAME);
if (dbfile.exists()) dbfile.delete();
openResponseHeaderDB(0);
}
private void openResponseHeaderDB(long preloadTime) {
// open the response header database
File dbfile = new File(this.cachePath, "responseHeader1.db");
File dbfile = new File(this.cachePath, DB_NAME);
this.responseHeaderDB = new kelondroMapObjects(new kelondroDyn(dbfile, true, true, preloadTime, yacySeedDB.commonHashLength, 150, '#', kelondroBase64Order.enhancedCoder, true, false, true), 500);
}