From 4437c8861c3a0815aa2f338df8676de21176a286 Mon Sep 17 00:00:00 2001 From: ForestL <45709305+ForestL18@users.noreply.github.com> Date: Fri, 11 Oct 2024 08:46:31 +0800 Subject: [PATCH] chore: better getUpdateTime() for iterating all Geofiles (#1570) --- component/updater/update_geo.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/component/updater/update_geo.go b/component/updater/update_geo.go index b5dc9677..bba0dabd 100644 --- a/component/updater/update_geo.go +++ b/component/updater/update_geo.go @@ -229,20 +229,22 @@ func UpdateGeoDatabases() error { } func getUpdateTime() (err error, time time.Time) { - var fileInfo os.FileInfo - if geodata.GeodataMode() { - fileInfo, err = os.Stat(C.Path.GeoIP()) - if err != nil { - return err, time - } - } else { - fileInfo, err = os.Stat(C.Path.MMDB()) - if err != nil { - return err, time + filesToCheck := []string{ + C.Path.GeoIP(), + C.Path.MMDB(), + C.Path.ASN(), + C.Path.GeoSite(), + } + + for _, file := range filesToCheck { + var fileInfo os.FileInfo + fileInfo, err = os.Stat(file) + if err == nil { + return nil, fileInfo.ModTime() } } - return nil, fileInfo.ModTime() + return } func RegisterGeoUpdater() {