From d664a9de1d27a375cb7ae42dad0a5db88b4d18bc Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 15 Mar 2019 16:09:43 +0300 Subject: [PATCH] - filter: update 'LastUpdated' field and 'last-modified' file time even when filter's content is up to date * filters: refactor: don't check 'LastUpdated' inside update() --- control.go | 2 +- filter.go | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/control.go b/control.go index ada72697..14b1506a 100644 --- a/control.go +++ b/control.go @@ -569,7 +569,7 @@ func handleFilteringAddURL(w http.ResponseWriter, r *http.Request) { f.Enabled = true // Download the filter contents - ok, err := f.update(true) + ok, err := f.update() if err != nil { httpError(w, http.StatusBadRequest, "Couldn't fetch filter from url %s: %s", f.URL, err) return diff --git a/filter.go b/filter.go index c294b3b5..45115414 100644 --- a/filter.go +++ b/filter.go @@ -179,7 +179,11 @@ func refreshFiltersIfNecessary(force bool) int { continue } - updated, err := filter.update(force) + if !force && time.Since(filter.LastUpdated) <= updatePeriod { + continue + } + + updated, err := filter.update() if err != nil { log.Printf("Failed to update filter %s: %s\n", filter.URL, err) continue @@ -193,6 +197,11 @@ func refreshFiltersIfNecessary(force bool) int { } updateCount++ + + } else { + mtime := time.Now() + os.Chtimes(filter.Path(), mtime, mtime) + filter.LastUpdated = mtime } } config.Unlock() @@ -236,14 +245,8 @@ func parseFilterContents(contents []byte) (int, string, []string) { return rulesCount, name, lines } -// Checks for filters updates -// If "force" is true -- does not check the filter's LastUpdated field -// Call "save" to persist the filter contents -func (filter *filter) update(force bool) (bool, error) { - if !force && time.Since(filter.LastUpdated) <= updatePeriod { - return false, nil - } - +// Perform upgrade on a filter +func (filter *filter) update() (bool, error) { log.Tracef("Downloading update for filter %d from %s", filter.ID, filter.URL) resp, err := client.Get(filter.URL)