From 67f31ccf4361645f990c1bad9051bce370c28524 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Mon, 21 Oct 2019 19:49:56 +0300 Subject: [PATCH 1/2] * minor --- home/filter.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/home/filter.go b/home/filter.go index 415ba783..72835a92 100644 --- a/home/filter.go +++ b/home/filter.go @@ -217,8 +217,12 @@ func refreshFilters() (int, error) { // . For each filter run the download and checksum check operation // . For each filter: // . If filter data hasn't changed, just set new update time on file -// . If filter data has changed: rename the old file, store the new data on disk -// . Pass new filters to dnsfilter object +// . If filter data has changed: +// . rename the old file (1.txt -> 1.txt.old) +// . store the new data on disk (1.txt) +// . Pass new filters to dnsfilter object - it analyzes new data while the old filters are still active +// . dnsfilter activates new filters +// . Remove the old filter files (1.txt.old) func refreshFiltersIfNecessary(force bool) int { var updateFilters []filter var updateFlags []bool // 'true' if filter data has changed @@ -431,7 +435,10 @@ func (filter *filter) save() error { func (filter *filter) saveAndBackupOld() error { filterFilePath := filter.Path() - _ = os.Rename(filterFilePath, filterFilePath+".old") + err := os.Rename(filterFilePath, filterFilePath+".old") + if err != nil { + return err + } return filter.save() } From 6ba1d857ac7961ed5a97a85a328398296c520273 Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 22 Oct 2019 14:58:20 +0300 Subject: [PATCH 2/2] * dnsfilter: windows: store rules in memory * dnsfilter: ignore cosmetic rules --- dnsfilter/dnsfilter.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index 2902c75a..eed6bd33 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -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) }