From 7465eaafa18b288b2e90d64794f25e57c09a3a5d Mon Sep 17 00:00:00 2001 From: Clash-Mini Date: Sun, 6 Feb 2022 04:30:54 +0800 Subject: [PATCH] [Fix]GeoSite.dat initial in logic rule --- config/config.go | 4 ++-- config/initial.go | 2 +- rule/logic/common.go | 7 +++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 8d9465ec..2ff509d4 100644 --- a/config/config.go +++ b/config/config.go @@ -556,7 +556,7 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin params = trimArr(params) if ruleName == "GEOSITE" { - if err := initGeoSite(); err != nil { + if err := InitGeoSite(); err != nil { return nil, nil, fmt.Errorf("can't initial GeoSite: %w", err) } } @@ -701,7 +701,7 @@ func parseFallbackIPCIDR(ips []string) ([]*net.IPNet, error) { func parseFallbackGeoSite(countries []string, rules []C.Rule) ([]*router.DomainMatcher, error) { var sites []*router.DomainMatcher if len(countries) > 0 { - if err := initGeoSite(); err != nil { + if err := InitGeoSite(); err != nil { return nil, fmt.Errorf("can't initial GeoSite: %w", err) } } diff --git a/config/initial.go b/config/initial.go index 5363d3ba..44225761 100644 --- a/config/initial.go +++ b/config/initial.go @@ -44,7 +44,7 @@ func downloadGeoSite(path string) (err error) { return err } -func initGeoSite() error { +func InitGeoSite() error { if _, err := os.Stat(C.Path.GeoSite()); os.IsNotExist(err) { log.Infoln("Need GeoSite but can't find GeoSite.dat, start download") if err := downloadGeoSite(C.Path.GeoSite()); err != nil { diff --git a/rule/logic/common.go b/rule/logic/common.go index 11d67915..524a7eb1 100644 --- a/rule/logic/common.go +++ b/rule/logic/common.go @@ -3,7 +3,9 @@ package logic import ( "fmt" "github.com/Dreamacro/clash/common/collections" + "github.com/Dreamacro/clash/config" C "github.com/Dreamacro/clash/constant" + "github.com/Dreamacro/clash/log" RC "github.com/Dreamacro/clash/rule/common" "github.com/Dreamacro/clash/rule/provider" "regexp" @@ -52,6 +54,11 @@ func payloadToRule(subPayload string) (C.Rule, error) { if tp == "NOT" || tp == "OR" || tp == "AND" { return parseRule(tp, payload, nil) } + if tp == "GEOSITE" { + if err := config.InitGeoSite(); err != nil { + log.Errorln("can't initial GeoSite: %w", err) + } + } param := strings.Split(payload, ",") return parseRule(tp, param[0], param[1:])