Skip to content

Commit 9c80c41

Browse files
committed
adopt path-in-bundle for rule-providers
1 parent 1452c27 commit 9c80c41

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

core/src/foss/golang/clash

core/src/main/golang/native/config/fetch.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"cfa/native/app"
1616

1717
clashHttp "github.com/metacubex/mihomo/component/http"
18+
RB "github.com/metacubex/mihomo/rules/bundle"
1819
)
1920

2021
type Status struct {
@@ -60,6 +61,10 @@ func fetch(url *U.URL, file string) error {
6061

6162
defer reader.Close()
6263

64+
return writeFile(file, reader)
65+
}
66+
67+
func writeFile(file string, reader io.Reader) error {
6368
_ = os.MkdirAll(P.Dir(file), 0700)
6469

6570
f, err := os.OpenFile(file, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0600)
@@ -145,6 +150,22 @@ func FetchAndValid(
145150
return
146151
}
147152

153+
if prefix == RULES {
154+
if pib, uok := provider["path-in-bundle"]; uok {
155+
if pib, uok := pib.(string); uok && pib != "" {
156+
// actually, we don't need to extract the file here; the core will do it.
157+
// however, due to historical reasons, CMFA fetches provider content when loading profile,
158+
// so we maintain consistency with the old behavior.
159+
if file, err := RB.Open(pib); err == nil {
160+
defer file.Close()
161+
if err := writeFile(ps, file); err == nil {
162+
return
163+
}
164+
}
165+
}
166+
}
167+
}
168+
148169
_ = fetch(url, ps)
149170
})
150171

0 commit comments

Comments
 (0)