Fix: provider fallback should reparse proxies

This commit is contained in:
Dreamacro 2020-02-22 15:17:43 +08:00
parent 609869bf5a
commit 9eaca6e4ab

View File

@ -114,10 +114,12 @@ func (pp *ProxySetProvider) Destroy() error {
func (pp *ProxySetProvider) Initial() error {
var buf []byte
var err error
var isLocal bool
if stat, err := os.Stat(pp.vehicle.Path()); err == nil {
buf, err = ioutil.ReadFile(pp.vehicle.Path())
modTime := stat.ModTime()
pp.updatedAt = &modTime
isLocal = true
} else {
buf, err = pp.vehicle.Read()
}
@ -128,11 +130,20 @@ func (pp *ProxySetProvider) Initial() error {
proxies, err := pp.parse(buf)
if err != nil {
if !isLocal {
return err
}
// parse local file error, fallback to remote
buf, err = pp.vehicle.Read()
if err != nil {
return err
}
proxies, err = pp.parse(buf)
if err != nil {
return err
}
}
if err := ioutil.WriteFile(pp.vehicle.Path(), buf, fileMode); err != nil {