diff --git a/app.go b/app.go index 91f4fbdd..232f1526 100644 --- a/app.go +++ b/app.go @@ -12,7 +12,6 @@ import ( "strconv" "sync" "syscall" - "time" "github.com/AdguardTeam/golibs/log" "github.com/gobuffalo/packr" @@ -101,24 +100,7 @@ func run(args options) { config.BindPort = args.bindPort } - // Load filters from the disk - // And if any filter has zero ID, assign a new one - for i := range config.Filters { - filter := &config.Filters[i] // otherwise we're operating on a copy - if filter.ID == 0 { - filter.ID = assignUniqueFilterID() - } - err = filter.load() - if err != nil { - // This is okay for the first start, the filter will be loaded later - log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) - // clear LastUpdated so it gets fetched right away - } - - if len(filter.Rules) == 0 { - filter.LastUpdated = time.Time{} - } - } + loadFilters() // Save the updated config err = config.write() diff --git a/filter.go b/filter.go index e8f68d43..e20ad45f 100644 --- a/filter.go +++ b/filter.go @@ -44,6 +44,27 @@ func userFilter() filter { } } +// Load filters from the disk +// And if any filter has zero ID, assign a new one +func loadFilters() { + for i := range config.Filters { + filter := &config.Filters[i] // otherwise we're operating on a copy + if filter.ID == 0 { + filter.ID = assignUniqueFilterID() + } + err := filter.load() + if err != nil { + // This is okay for the first start, the filter will be loaded later + log.Debug("Couldn't load filter %d contents due to %s", filter.ID, err) + // clear LastUpdated so it gets fetched right away + } + + if len(filter.Rules) == 0 { + filter.LastUpdated = time.Time{} + } + } +} + func deduplicateFilters() { // Deduplicate filters i := 0 // output index, used for deletion later