chore: 优化GeoSite初始化代码
This commit is contained in:
@ -583,13 +583,6 @@ func parseRules(cfg *RawConfig, proxies map[string]C.Proxy) ([]C.Rule, map[strin
|
||||
}
|
||||
|
||||
params = trimArr(params)
|
||||
|
||||
if ruleName == "GEOSITE" {
|
||||
if err := initGeoSite(); err != nil {
|
||||
return nil, nil, fmt.Errorf("can't initial GeoSite: %s", err)
|
||||
}
|
||||
initMode = false
|
||||
}
|
||||
parsed, parseErr := R.ParseRule(ruleName, payload, target, params)
|
||||
if parseErr != nil {
|
||||
return nil, nil, fmt.Errorf("rules[%d] [%s] error: %s", idx, line, parseErr.Error())
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/Dreamacro/clash/log"
|
||||
)
|
||||
|
||||
var initMode = true
|
||||
var initFlag bool
|
||||
|
||||
func downloadMMDB(path string) (err error) {
|
||||
resp, err := http.Get(C.MmdbUrl)
|
||||
@ -73,7 +73,7 @@ func initGeoSite() error {
|
||||
}
|
||||
log.Infoln("Download GeoSite.dat finish")
|
||||
}
|
||||
if initMode {
|
||||
if !initFlag {
|
||||
if err := geodata.Verify(C.GeositeName); err != nil {
|
||||
log.Warnln("GeoSite.dat invalid, remove and download: %s", err)
|
||||
if err := os.Remove(C.Path.GeoSite()); err != nil {
|
||||
@ -83,6 +83,7 @@ func initGeoSite() error {
|
||||
return fmt.Errorf("can't download GeoSite.dat: %s", err.Error())
|
||||
}
|
||||
}
|
||||
initFlag = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user