From 9415444ebdb454c6bb8ab0adf457118c90f34a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 5 Oct 2024 09:28:58 +0800 Subject: [PATCH] Fix base path not applied to local rule-sets --- route/rule_set.go | 2 +- route/rule_set_local.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/route/rule_set.go b/route/rule_set.go index f644fb40..fda3d105 100644 --- a/route/rule_set.go +++ b/route/rule_set.go @@ -18,7 +18,7 @@ import ( func NewRuleSet(ctx context.Context, router adapter.Router, logger logger.ContextLogger, options option.RuleSet) (adapter.RuleSet, error) { switch options.Type { case C.RuleSetTypeLocal: - return NewLocalRuleSet(router, options) + return NewLocalRuleSet(ctx, router, options) case C.RuleSetTypeRemote: return NewRemoteRuleSet(ctx, router, logger, options), nil default: diff --git a/route/rule_set_local.go b/route/rule_set_local.go index 39458267..07839c65 100644 --- a/route/rule_set_local.go +++ b/route/rule_set_local.go @@ -12,6 +12,7 @@ import ( E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" "github.com/sagernet/sing/common/json" + "github.com/sagernet/sing/service/filemanager" ) var _ adapter.RuleSet = (*LocalRuleSet)(nil) @@ -21,11 +22,11 @@ type LocalRuleSet struct { 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 switch options.Format { case C.RuleSetFormatSource, "": - content, err := os.ReadFile(options.LocalOptions.Path) + content, err := os.ReadFile(filemanager.BasePath(ctx, options.LocalOptions.Path)) if err != nil { return nil, err } @@ -35,7 +36,7 @@ func NewLocalRuleSet(router adapter.Router, options option.RuleSet) (*LocalRuleS } plainRuleSet = compat.Upgrade() case C.RuleSetFormatBinary: - setFile, err := os.Open(options.LocalOptions.Path) + setFile, err := os.Open(filemanager.BasePath(ctx, options.LocalOptions.Path)) if err != nil { return nil, err }