* dnsfilter: windows: store rules in memory

* dnsfilter: ignore cosmetic rules
This commit is contained in:
Simon Zolin 2019-10-22 14:58:20 +03:00
parent 67f31ccf43
commit 6ba1d857ac
1 changed files with 17 additions and 3 deletions

View File

@ -13,6 +13,7 @@ import (
"net"
"net/http"
"os"
"runtime"
"strings"
"sync"
"sync/atomic"
@ -772,18 +773,31 @@ func (d *Dnsfilter) initFiltering(filters map[int]string) error {
list = &urlfilter.StringRuleList{
ID: 0,
RulesText: dataOrFilePath,
IgnoreCosmetic: false,
IgnoreCosmetic: true,
}
} else if !fileExists(dataOrFilePath) {
list = &urlfilter.StringRuleList{
ID: id,
IgnoreCosmetic: false,
IgnoreCosmetic: true,
}
} else if runtime.GOOS == "windows" {
// On Windows we don't pass a file to urlfilter because
// it's difficult to update this file while it's being used.
data, err := ioutil.ReadFile(dataOrFilePath)
if err != nil {
return fmt.Errorf("ioutil.ReadFile(): %s: %s", dataOrFilePath, err)
}
list = &urlfilter.StringRuleList{
ID: id,
RulesText: string(data),
IgnoreCosmetic: true,
}
} else {
var err error
list, err = urlfilter.NewFileRuleList(id, dataOrFilePath, false)
list, err = urlfilter.NewFileRuleList(id, dataOrFilePath, true)
if err != nil {
return fmt.Errorf("urlfilter.NewFileRuleList(): %s: %s", dataOrFilePath, err)
}