From 9eaca6e4ab4ccf584d6ced0da56dc5a9c82a2b52 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Sat, 22 Feb 2020 15:17:43 +0800 Subject: [PATCH] Fix: provider fallback should reparse proxies --- adapters/provider/provider.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/adapters/provider/provider.go b/adapters/provider/provider.go index fef148a4..8ec4a108 100644 --- a/adapters/provider/provider.go +++ b/adapters/provider/provider.go @@ -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 {