mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 03:51:31 +00:00
Fix download geo resources
This commit is contained in:
parent
98bf696d01
commit
8140af01aa
|
@ -52,13 +52,15 @@ func (r *Router) prepareGeoIPDatabase() error {
|
||||||
geoPath = foundPath
|
geoPath = foundPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !rw.FileExists(geoPath) {
|
||||||
geoPath = filemanager.BasePath(r.ctx, geoPath)
|
geoPath = filemanager.BasePath(r.ctx, geoPath)
|
||||||
if rw.FileExists(geoPath) {
|
}
|
||||||
geoReader, codes, err := geoip.Open(geoPath)
|
if stat, err := os.Stat(geoPath); err == nil {
|
||||||
if err == nil {
|
if stat.IsDir() {
|
||||||
r.logger.Info("loaded geoip database: ", len(codes), " codes")
|
return E.New("geoip path is a directory: ", geoPath)
|
||||||
r.geoIPReader = geoReader
|
}
|
||||||
return nil
|
if stat.Size() == 0 {
|
||||||
|
os.Remove(geoPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !rw.FileExists(geoPath) {
|
if !rw.FileExists(geoPath) {
|
||||||
|
@ -96,7 +98,17 @@ func (r *Router) prepareGeositeDatabase() error {
|
||||||
geoPath = foundPath
|
geoPath = foundPath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !rw.FileExists(geoPath) {
|
||||||
geoPath = filemanager.BasePath(r.ctx, geoPath)
|
geoPath = filemanager.BasePath(r.ctx, geoPath)
|
||||||
|
}
|
||||||
|
if stat, err := os.Stat(geoPath); err == nil {
|
||||||
|
if stat.IsDir() {
|
||||||
|
return E.New("geoip path is a directory: ", geoPath)
|
||||||
|
}
|
||||||
|
if stat.Size() == 0 {
|
||||||
|
os.Remove(geoPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
if !rw.FileExists(geoPath) {
|
if !rw.FileExists(geoPath) {
|
||||||
r.logger.Warn("geosite database not exists: ", geoPath)
|
r.logger.Warn("geosite database not exists: ", geoPath)
|
||||||
var err error
|
var err error
|
||||||
|
@ -107,7 +119,6 @@ func (r *Router) prepareGeositeDatabase() error {
|
||||||
}
|
}
|
||||||
r.logger.Error("download geosite database: ", err)
|
r.logger.Error("download geosite database: ", err)
|
||||||
os.Remove(geoPath)
|
os.Remove(geoPath)
|
||||||
// time.Sleep(10 * time.Second)
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue