mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +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 {
|
||||
once.Do(func() {
|
||||
mmdbPath := C.Path.MMDB()
|
||||
log.Debugln("Load MMDB file: %s", mmdbPath)
|
||||
log.Infoln("Load MMDB file: %s", mmdbPath)
|
||||
mmdb, err := maxminddb.Open(mmdbPath)
|
||||
if err != nil {
|
||||
log.Fatalln("Can't load MMDB: %s", err.Error())
|
||||
|
@ -94,3 +94,7 @@ func DownloadMMDB(path string) (err error) {
|
|||
|
||||
return err
|
||||
}
|
||||
|
||||
func Reload() {
|
||||
once = sync.Once{}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
|
||||
"github.com/metacubex/mihomo/component/geodata"
|
||||
_ "github.com/metacubex/mihomo/component/geodata/standard"
|
||||
"github.com/metacubex/mihomo/component/mmdb"
|
||||
C "github.com/metacubex/mihomo/constant"
|
||||
|
||||
"github.com/oschwald/maxminddb-golang"
|
||||
|
@ -33,6 +34,7 @@ func UpdateGeoDatabases() error {
|
|||
}
|
||||
|
||||
} else {
|
||||
defer mmdb.Reload()
|
||||
data, err := downloadForBytes(C.MmdbUrl)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
_ = 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 {
|
||||
return fmt.Errorf("can't save MMDB database file: %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user