Merge: - dnsfilter: fix post-install error "filter file not found"
* commit 'b0cfd7228eaae0719f40d37f766c541c06bfb1b0': - dnsfilter: fix post-install error "filter file not found"
This commit is contained in:
commit
4af635e58a
@ -11,6 +11,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -525,17 +526,34 @@ func (d *Dnsfilter) lookupCommon(host string, lookupstats *LookupStats, cache gc
|
|||||||
// Adding rule and matching against the rules
|
// Adding rule and matching against the rules
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// Return TRUE if file exists
|
||||||
|
func fileExists(fn string) bool {
|
||||||
|
_, err := os.Stat(fn)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize urlfilter objects
|
// Initialize urlfilter objects
|
||||||
func (d *Dnsfilter) initFiltering(filters map[int]string) error {
|
func (d *Dnsfilter) initFiltering(filters map[int]string) error {
|
||||||
listArray := []urlfilter.RuleList{}
|
listArray := []urlfilter.RuleList{}
|
||||||
for id, dataOrFilePath := range filters {
|
for id, dataOrFilePath := range filters {
|
||||||
var list urlfilter.RuleList
|
var list urlfilter.RuleList
|
||||||
|
|
||||||
if id == 0 {
|
if id == 0 {
|
||||||
list = &urlfilter.StringRuleList{
|
list = &urlfilter.StringRuleList{
|
||||||
ID: 0,
|
ID: 0,
|
||||||
RulesText: dataOrFilePath,
|
RulesText: dataOrFilePath,
|
||||||
IgnoreCosmetic: false,
|
IgnoreCosmetic: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if !fileExists(dataOrFilePath) {
|
||||||
|
list = &urlfilter.StringRuleList{
|
||||||
|
ID: id,
|
||||||
|
IgnoreCosmetic: false,
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
list, err = urlfilter.NewFileRuleList(id, dataOrFilePath, false)
|
list, err = urlfilter.NewFileRuleList(id, dataOrFilePath, false)
|
||||||
|
Loading…
Reference in New Issue
Block a user