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) } 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() }