mirror of
https://github.com/cmz0228/hysteria-dev.git
synced 2025-06-08 13:29:53 +00:00
feat: re-download geo db when autoDL && load fail
This commit is contained in:
parent
e22aa0630b
commit
6dea0adb19
@ -43,6 +43,10 @@ func (l *GeoLoader) shouldDownload(filename string) bool {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
if info.Size() == 0 {
|
||||||
|
// empty files are loadable by v2geo, but we consider it broken
|
||||||
|
return true
|
||||||
|
}
|
||||||
dt := time.Now().Sub(info.ModTime())
|
dt := time.Now().Sub(info.ModTime())
|
||||||
if l.UpdateInterval == 0 {
|
if l.UpdateInterval == 0 {
|
||||||
return dt > geoDefaultUpdateInterval
|
return dt > geoDefaultUpdateInterval
|
||||||
@ -101,7 +105,15 @@ func (l *GeoLoader) LoadGeoIP() (map[string]*v2geo.GeoIP, error) {
|
|||||||
autoDL = true
|
autoDL = true
|
||||||
filename = geoipFilename
|
filename = geoipFilename
|
||||||
}
|
}
|
||||||
if autoDL && l.shouldDownload(filename) {
|
if autoDL {
|
||||||
|
if !l.shouldDownload(filename) {
|
||||||
|
m, err := v2geo.LoadGeoIP(filename)
|
||||||
|
if err == nil {
|
||||||
|
l.geoipMap = m
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
// file is broken, download it again
|
||||||
|
}
|
||||||
err := l.downloadAndCheck(filename, geoipURL, func(filename string) error {
|
err := l.downloadAndCheck(filename, geoipURL, func(filename string) error {
|
||||||
_, err := v2geo.LoadGeoIP(filename)
|
_, err := v2geo.LoadGeoIP(filename)
|
||||||
return err
|
return err
|
||||||
@ -128,7 +140,15 @@ func (l *GeoLoader) LoadGeoSite() (map[string]*v2geo.GeoSite, error) {
|
|||||||
autoDL = true
|
autoDL = true
|
||||||
filename = geositeFilename
|
filename = geositeFilename
|
||||||
}
|
}
|
||||||
if autoDL && l.shouldDownload(filename) {
|
if autoDL {
|
||||||
|
if !l.shouldDownload(filename) {
|
||||||
|
m, err := v2geo.LoadGeoSite(filename)
|
||||||
|
if err == nil {
|
||||||
|
l.geositeMap = m
|
||||||
|
return m, nil
|
||||||
|
}
|
||||||
|
// file is broken, download it again
|
||||||
|
}
|
||||||
err := l.downloadAndCheck(filename, geositeURL, func(filename string) error {
|
err := l.downloadAndCheck(filename, geositeURL, func(filename string) error {
|
||||||
_, err := v2geo.LoadGeoSite(filename)
|
_, err := v2geo.LoadGeoSite(filename)
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user