Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
PublicAndroidApps
Nebulo
Commits
55bbcf0c
Commit
55bbcf0c
authored
Sep 05, 2020
by
Daniel Wolf
Browse files
Don't abort importing a list if at least one successful parser has been found
parent
57b09bb6
Changes
1
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/com/frostnerd/smokescreen/service/RuleImportService.kt
View file @
55bbcf0c
...
@@ -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,12 +305,16 @@ class RuleImportService : IntentService("RuleImportService") {
...
@@ -303,12 +305,16 @@ class RuleImportService : IntentService("RuleImportService") {
lineCount
=
0
lineCount
=
0
}
}
}
else
{
}
else
{
if
(
hosts
.
first
>
5
)
{
// If validParsings is at least 26 we know for sure that the current active parser had at least 5 successful hits
log
(
"Matcher $matcher failed 5 times, last for '$line'. Removing."
)
// So we are going to keep it for the rest of the document, even if it fails
iterator
.
remove
()
if
(
validParsings
<=
25
)
{
}
else
parsers
[
matcher
]
=
hosts
.
copy
(
hosts
.
first
+
1
)
if
(
hosts
.
first
>
5
)
{
if
(
parsers
.
isEmpty
())
{
log
(
"Matcher $matcher failed 5 times, last for '$line'. Removing."
)
log
(
"No parsers left. Aborting."
)
iterator
.
remove
()
}
else
parsers
[
matcher
]
=
hosts
.
copy
(
hosts
.
first
+
1
)
if
(
parsers
.
isEmpty
())
{
log
(
"No parsers left. Aborting."
)
}
}
}
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment