mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 20:52:15 +08:00
fix: update mmdb fail
This commit is contained in:
parent
3d833ef6a8
commit
f8295a02fd
@ -57,7 +57,7 @@ func Verify() bool {
|
|||||||
func Instance() Reader {
|
func Instance() Reader {
|
||||||
once.Do(func() {
|
once.Do(func() {
|
||||||
mmdbPath := C.Path.MMDB()
|
mmdbPath := C.Path.MMDB()
|
||||||
log.Debugln("Load MMDB file: %s", mmdbPath)
|
log.Infoln("Load MMDB file: %s", mmdbPath)
|
||||||
mmdb, err := maxminddb.Open(mmdbPath)
|
mmdb, err := maxminddb.Open(mmdbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Can't load MMDB: %s", err.Error())
|
log.Fatalln("Can't load MMDB: %s", err.Error())
|
||||||
@ -94,3 +94,7 @@ func DownloadMMDB(path string) (err error) {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Reload() {
|
||||||
|
once = sync.Once{}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/metacubex/mihomo/component/geodata"
|
"github.com/metacubex/mihomo/component/geodata"
|
||||||
_ "github.com/metacubex/mihomo/component/geodata/standard"
|
_ "github.com/metacubex/mihomo/component/geodata/standard"
|
||||||
|
"github.com/metacubex/mihomo/component/mmdb"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
|
||||||
"github.com/oschwald/maxminddb-golang"
|
"github.com/oschwald/maxminddb-golang"
|
||||||
@ -33,6 +34,7 @@ func UpdateGeoDatabases() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
defer mmdb.Reload()
|
||||||
data, err := downloadForBytes(C.MmdbUrl)
|
data, err := downloadForBytes(C.MmdbUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't download MMDB database file: %w", err)
|
return fmt.Errorf("can't download MMDB database file: %w", err)
|
||||||
@ -43,6 +45,8 @@ func UpdateGeoDatabases() error {
|
|||||||
return fmt.Errorf("invalid MMDB database file: %s", err)
|
return fmt.Errorf("invalid MMDB database file: %s", err)
|
||||||
}
|
}
|
||||||
_ = instance.Close()
|
_ = instance.Close()
|
||||||
|
|
||||||
|
mmdb.Instance().Reader.Close() // mmdb is loaded with mmap, so it needs to be closed before overwriting the file
|
||||||
if err = saveFile(data, C.Path.MMDB()); err != nil {
|
if err = saveFile(data, C.Path.MMDB()); err != nil {
|
||||||
return fmt.Errorf("can't save MMDB database file: %w", err)
|
return fmt.Errorf("can't save MMDB database file: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user