Skip to content

Commit

Permalink
Fixed (?i) appearing in entries, fixed multiple equal lines in file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Ableitner committed Jul 17, 2013
1 parent 376f9cd commit 0304458
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions source/net/yacy/repository/Blacklist.java
Expand Up @@ -232,15 +232,15 @@ private void loadList(final BlacklistFile blFile, final String sep) {
loadedPathsPattern = new HashSet<Pattern>();
for (String a: loadedPaths) {
if (a.equals("*")) {
loadedPathsPattern.add(Pattern.compile("(?i).*"));
loadedPathsPattern.add(Pattern.compile(".*", Pattern.CASE_INSENSITIVE));
continue;
}
if (a.indexOf("?*", 0) > 0) {
// prevent "Dangling meta character '*'" exception
ConcurrentLog.warn("Blacklist", "ignored blacklist path to prevent 'Dangling meta character' exception: " + a);
continue;
}
loadedPathsPattern.add(Pattern.compile("(?i)" + a)); // add case insesitive regex
loadedPathsPattern.add(Pattern.compile(a, Pattern.CASE_INSENSITIVE)); // add case insesitive regex
}

// create new entry if host mask unknown, otherwise merge
Expand Down Expand Up @@ -348,29 +348,31 @@ public final void add(final BlacklistType blacklistType, final String host, fina
blacklistMap.put(h, (hostList = new HashSet<Pattern>()));
}

// Create add case insesitive regex
Pattern pattern = Pattern.compile("(?i)" + p);
Pattern pattern = Pattern.compile(p, Pattern.CASE_INSENSITIVE);

hostList.add(pattern);
// append the line to the file

// Append the line to the file.
PrintWriter pw = null;
try {
pw = new PrintWriter(new FileWriter(new File(blacklistRootPath, getFileName(blacklistType)), true));
pw.println(pattern);
pw.close();
try {
if (!blacklistFileContains(blacklistRootPath,
getFileName(blacklistType), pattern.toString())) {
pw = new PrintWriter(new FileWriter(new File(blacklistRootPath,
getFileName(blacklistType)), true));
pw.println(pattern);
pw.close();
}
} catch (final IOException e) {
ConcurrentLog.logException(e);
} finally {
if (pw != null) {
if (pw != null) {
try {
pw.close();
pw.close();
} catch (final Exception e) {
ConcurrentLog.warn("Blacklist", "could not close stream to " +
getFileName(blacklistType) + "! " + e.getMessage());
}

}
}
}
}

Expand Down

0 comments on commit 0304458

Please sign in to comment.