summaryrefslogtreecommitdiff
path: root/plugin/singbox
diff options
context:
space:
mode:
authorLoyalsoldier <[email protected]>2024-07-06 18:04:33 +0800
committerLoyalsoldier <[email protected]>2024-07-06 18:04:33 +0800
commite3800440ce05aa1b8f27d56f47bbeef20f9499c6 (patch)
tree5c85e84b7c02713b75738649e483b5758027d011 /plugin/singbox
parent5843ee29c435b393bec57a367775c2f4e266eedc (diff)
Fix: remove entry & prefix
Diffstat (limited to 'plugin/singbox')
-rw-r--r--plugin/singbox/srs_in.go29
1 files changed, 12 insertions, 17 deletions
diff --git a/plugin/singbox/srs_in.go b/plugin/singbox/srs_in.go
index 343fd4ca..44812cb8 100644
--- a/plugin/singbox/srs_in.go
+++ b/plugin/singbox/srs_in.go
@@ -114,7 +114,7 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
}
if len(entries) == 0 {
- return nil, fmt.Errorf("type %s | action %s no entry are generated", s.Type, s.Action)
+ return nil, fmt.Errorf("type %s | action %s no entry is generated", s.Type, s.Action)
}
for _, entry := range entries {
@@ -124,7 +124,11 @@ func (s *srsIn) Input(container lib.Container) (lib.Container, error) {
return nil, err
}
case lib.ActionRemove:
- container.Remove(entry.GetName(), ignoreIPType)
+ if err := container.Remove(entry, lib.CaseRemovePrefix, ignoreIPType); err != nil {
+ return nil, err
+ }
+ default:
+ return nil, lib.ErrUnknownAction
}
}
@@ -200,10 +204,9 @@ func (s *srsIn) walkRemoteFile(url, name string, entries map[string]*lib.Entry)
}
func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[string]*lib.Entry) error {
- entry := lib.NewEntry(name)
- if theEntry, found := entries[entry.GetName()]; found {
- fmt.Printf("⚠️ [type %s | action %s] found duplicated entry: %s. Process anyway\n", typeSRSIn, s.Action, name)
- entry = theEntry
+ entry, found := entries[name]
+ if !found {
+ entry = lib.NewEntry(name)
}
plainRuleSet, err := srs.Read(reader, true)
@@ -213,20 +216,12 @@ func (s *srsIn) generateEntries(name string, reader io.Reader, entries map[strin
for _, rule := range plainRuleSet.Rules {
for _, cidrStr := range rule.DefaultOptions.IPCIDR {
- switch s.Action {
- case lib.ActionAdd:
- if err := entry.AddPrefix(cidrStr); err != nil {
- return err
- }
- case lib.ActionRemove:
- if err := entry.RemovePrefix(cidrStr); err != nil {
- return err
- }
+ if err := entry.AddPrefix(cidrStr); err != nil {
+ return err
}
}
}
- entries[entry.GetName()] = entry
-
+ entries[name] = entry
return nil
}