@@ -52,13 +52,15 @@ func (r *Router) prepareGeoIPDatabase() error {
52
52
geoPath = foundPath
53
53
}
54
54
}
55
- geoPath = filemanager .BasePath (r .ctx , geoPath )
56
- if rw .FileExists (geoPath ) {
57
- geoReader , codes , err := geoip .Open (geoPath )
58
- if err == nil {
59
- r .logger .Info ("loaded geoip database: " , len (codes ), " codes" )
60
- r .geoIPReader = geoReader
61
- return nil
55
+ if ! rw .FileExists (geoPath ) {
56
+ geoPath = filemanager .BasePath (r .ctx , geoPath )
57
+ }
58
+ if stat , err := os .Stat (geoPath ); err == nil {
59
+ if stat .IsDir () {
60
+ return E .New ("geoip path is a directory: " , geoPath )
61
+ }
62
+ if stat .Size () == 0 {
63
+ os .Remove (geoPath )
62
64
}
63
65
}
64
66
if ! rw .FileExists (geoPath ) {
@@ -96,7 +98,17 @@ func (r *Router) prepareGeositeDatabase() error {
96
98
geoPath = foundPath
97
99
}
98
100
}
99
- geoPath = filemanager .BasePath (r .ctx , geoPath )
101
+ if ! rw .FileExists (geoPath ) {
102
+ geoPath = filemanager .BasePath (r .ctx , geoPath )
103
+ }
104
+ if stat , err := os .Stat (geoPath ); err == nil {
105
+ if stat .IsDir () {
106
+ return E .New ("geoip path is a directory: " , geoPath )
107
+ }
108
+ if stat .Size () == 0 {
109
+ os .Remove (geoPath )
110
+ }
111
+ }
100
112
if ! rw .FileExists (geoPath ) {
101
113
r .logger .Warn ("geosite database not exists: " , geoPath )
102
114
var err error
@@ -107,7 +119,6 @@ func (r *Router) prepareGeositeDatabase() error {
107
119
}
108
120
r .logger .Error ("download geosite database: " , err )
109
121
os .Remove (geoPath )
110
- // time.Sleep(10 * time.Second)
111
122
}
112
123
if err != nil {
113
124
return err
0 commit comments