Commit 55bbcf0c authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Don't abort importing a list if at least one successful parser has been found

parent 57b09bb6
...@@ -286,6 +286,7 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -286,6 +286,7 @@ class RuleImportService : IntentService("RuleImportService") {
var ruleCount = 0 var ruleCount = 0
val sourceId = source.id val sourceId = source.id
BufferedReader(InputStreamReader(stream)).useLines { lines -> BufferedReader(InputStreamReader(stream)).useLines { lines ->
var validParsings = 0
lines.forEach { _line -> lines.forEach { _line ->
val line = _line.trim() val line = _line.trim()
if (!isAborted) { if (!isAborted) {
...@@ -294,6 +295,7 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -294,6 +295,7 @@ class RuleImportService : IntentService("RuleImportService") {
val iterator = parsers.iterator() val iterator = parsers.iterator()
for ((matcher, hosts) in iterator) { for ((matcher, hosts) in iterator) {
if (matcher.reset(line).matches()) { if (matcher.reset(line).matches()) {
validParsings++
val rule = processLine(matcher, sourceId, source.whitelistSource) val rule = processLine(matcher, sourceId, source.whitelistSource)
if (rule != null) hosts.second.add(rule.apply { if (rule != null) hosts.second.add(rule.apply {
stagingType = 2 stagingType = 2
...@@ -303,6 +305,9 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -303,6 +305,9 @@ class RuleImportService : IntentService("RuleImportService") {
lineCount = 0 lineCount = 0
} }
} else { } else {
// If validParsings is at least 26 we know for sure that the current active parser had at least 5 successful hits
// So we are going to keep it for the rest of the document, even if it fails
if(validParsings <= 25) {
if (hosts.first > 5) { if (hosts.first > 5) {
log("Matcher $matcher failed 5 times, last for '$line'. Removing.") log("Matcher $matcher failed 5 times, last for '$line'. Removing.")
iterator.remove() iterator.remove()
...@@ -313,6 +318,7 @@ class RuleImportService : IntentService("RuleImportService") { ...@@ -313,6 +318,7 @@ class RuleImportService : IntentService("RuleImportService") {
} }
} }
} }
}
} else { } else {
return@useLines return@useLines
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment