Skip to content

Commit

Permalink
Fix download geo resources
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jul 20, 2023
1 parent 98bf696 commit 8140af0
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions route/router_geo_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ func (r *Router) prepareGeoIPDatabase() error {
geoPath = foundPath
}
}
geoPath = filemanager.BasePath(r.ctx, geoPath)
if rw.FileExists(geoPath) {
geoReader, codes, err := geoip.Open(geoPath)
if err == nil {
r.logger.Info("loaded geoip database: ", len(codes), " codes")
r.geoIPReader = geoReader
return nil
if !rw.FileExists(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) {
Expand Down Expand Up @@ -96,7 +98,17 @@ func (r *Router) prepareGeositeDatabase() error {
geoPath = foundPath
}
}
geoPath = filemanager.BasePath(r.ctx, geoPath)
if !rw.FileExists(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) {
r.logger.Warn("geosite database not exists: ", geoPath)
var err error
Expand All @@ -107,7 +119,6 @@ func (r *Router) prepareGeositeDatabase() error {
}
r.logger.Error("download geosite database: ", err)
os.Remove(geoPath)
// time.Sleep(10 * time.Second)
}
if err != nil {
return err
Expand Down

0 comments on commit 8140af0

Please sign in to comment.