fix: exclude-filter not work when filter is empty

This commit is contained in:
gVisor bot 2022-11-09 08:41:30 +08:00
parent a3d4385a90
commit b1802da5ea

View file

@ -71,59 +71,54 @@ func (gb *GroupBase) Touch() {
} }
func (gb *GroupBase) GetProxies(touch bool) []C.Proxy { func (gb *GroupBase) GetProxies(touch bool) []C.Proxy {
var proxies []C.Proxy
if len(gb.filterRegs) == 0 { if len(gb.filterRegs) == 0 {
var proxies []C.Proxy
for _, pd := range gb.providers { for _, pd := range gb.providers {
if touch { if touch {
pd.Touch() pd.Touch()
} }
proxies = append(proxies, pd.Proxies()...) proxies = append(proxies, pd.Proxies()...)
} }
if len(proxies) == 0 { } else {
return append(proxies, tunnel.Proxies()["COMPATIBLE"]) for i, pd := range gb.providers {
} if touch {
return proxies pd.Touch()
} }
for i, pd := range gb.providers { if pd.VehicleType() == types.Compatible {
if touch { gb.versions[i].Store(pd.Version())
pd.Touch() gb.proxies[i] = pd.Proxies()
} continue
}
if pd.VehicleType() == types.Compatible { version := gb.versions[i].Load()
gb.versions[i].Store(pd.Version()) if version != pd.Version() && gb.versions[i].CompareAndSwap(version, pd.Version()) {
gb.proxies[i] = pd.Proxies() var (
continue proxies []C.Proxy
} newProxies []C.Proxy
)
version := gb.versions[i].Load() proxies = pd.Proxies()
if version != pd.Version() && gb.versions[i].CompareAndSwap(version, pd.Version()) { proxiesSet := map[string]struct{}{}
var ( for _, filterReg := range gb.filterRegs {
proxies []C.Proxy for _, p := range proxies {
newProxies []C.Proxy name := p.Name()
) if mat, _ := filterReg.FindStringMatch(name); mat != nil {
if _, ok := proxiesSet[name]; !ok {
proxies = pd.Proxies() proxiesSet[name] = struct{}{}
proxiesSet := map[string]struct{}{} newProxies = append(newProxies, p)
for _, filterReg := range gb.filterRegs { }
for _, p := range proxies {
name := p.Name()
if mat, _ := filterReg.FindStringMatch(name); mat != nil {
if _, ok := proxiesSet[name]; !ok {
proxiesSet[name] = struct{}{}
newProxies = append(newProxies, p)
} }
} }
} }
gb.proxies[i] = newProxies
} }
gb.proxies[i] = newProxies
} }
}
var proxies []C.Proxy for _, p := range gb.proxies {
for _, p := range gb.proxies { proxies = append(proxies, p...)
proxies = append(proxies, p...) }
} }
if len(proxies) == 0 { if len(proxies) == 0 {