mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-26 02:21:28 +00:00
Fix base path not applied to local rule-sets
This commit is contained in:
parent
95606191d8
commit
9415444ebd
|
@ -18,7 +18,7 @@ import (
|
||||||
func NewRuleSet(ctx context.Context, router adapter.Router, logger logger.ContextLogger, options option.RuleSet) (adapter.RuleSet, error) {
|
func NewRuleSet(ctx context.Context, router adapter.Router, logger logger.ContextLogger, options option.RuleSet) (adapter.RuleSet, error) {
|
||||||
switch options.Type {
|
switch options.Type {
|
||||||
case C.RuleSetTypeLocal:
|
case C.RuleSetTypeLocal:
|
||||||
return NewLocalRuleSet(router, options)
|
return NewLocalRuleSet(ctx, router, options)
|
||||||
case C.RuleSetTypeRemote:
|
case C.RuleSetTypeRemote:
|
||||||
return NewRemoteRuleSet(ctx, router, logger, options), nil
|
return NewRemoteRuleSet(ctx, router, logger, options), nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
F "github.com/sagernet/sing/common/format"
|
F "github.com/sagernet/sing/common/format"
|
||||||
"github.com/sagernet/sing/common/json"
|
"github.com/sagernet/sing/common/json"
|
||||||
|
"github.com/sagernet/sing/service/filemanager"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ adapter.RuleSet = (*LocalRuleSet)(nil)
|
var _ adapter.RuleSet = (*LocalRuleSet)(nil)
|
||||||
|
@ -21,11 +22,11 @@ type LocalRuleSet struct {
|
||||||
metadata adapter.RuleSetMetadata
|
metadata adapter.RuleSetMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalRuleSet(router adapter.Router, options option.RuleSet) (*LocalRuleSet, error) {
|
func NewLocalRuleSet(ctx context.Context, router adapter.Router, options option.RuleSet) (*LocalRuleSet, error) {
|
||||||
var plainRuleSet option.PlainRuleSet
|
var plainRuleSet option.PlainRuleSet
|
||||||
switch options.Format {
|
switch options.Format {
|
||||||
case C.RuleSetFormatSource, "":
|
case C.RuleSetFormatSource, "":
|
||||||
content, err := os.ReadFile(options.LocalOptions.Path)
|
content, err := os.ReadFile(filemanager.BasePath(ctx, options.LocalOptions.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ func NewLocalRuleSet(router adapter.Router, options option.RuleSet) (*LocalRuleS
|
||||||
}
|
}
|
||||||
plainRuleSet = compat.Upgrade()
|
plainRuleSet = compat.Upgrade()
|
||||||
case C.RuleSetFormatBinary:
|
case C.RuleSetFormatBinary:
|
||||||
setFile, err := os.Open(options.LocalOptions.Path)
|
setFile, err := os.Open(filemanager.BasePath(ctx, options.LocalOptions.Path))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue