修复了规则更新后没有生效的问题
This commit is contained in:
@@ -813,6 +813,7 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
// 尝试删除域名规则
|
||||
domain := strings.TrimPrefix(format, "||")
|
||||
if _, exists := m.domainRules[domain]; exists {
|
||||
// 删除主域名规则
|
||||
delete(m.domainRules, domain)
|
||||
delete(m.domainRulesIsLocal, domain)
|
||||
delete(m.domainRulesSource, domain)
|
||||
@@ -822,6 +823,7 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
} else {
|
||||
// 尝试直接作为域名删除
|
||||
if _, exists := m.domainRules[format]; exists {
|
||||
// 删除主域名规则
|
||||
delete(m.domainRules, format)
|
||||
delete(m.domainRulesIsLocal, format)
|
||||
delete(m.domainRulesSource, format)
|
||||
@@ -829,6 +831,7 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
break
|
||||
}
|
||||
if _, exists := m.domainExceptions[format]; exists {
|
||||
// 删除主排除规则
|
||||
delete(m.domainExceptions, format)
|
||||
delete(m.domainExceptionsIsLocal, format)
|
||||
delete(m.domainExceptionsSource, format)
|
||||
@@ -871,6 +874,8 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
for domain := range m.domainRules {
|
||||
if domain == cleanRule || domain == rule {
|
||||
delete(m.domainRules, domain)
|
||||
delete(m.domainRulesIsLocal, domain)
|
||||
delete(m.domainRulesSource, domain)
|
||||
removed = true
|
||||
break
|
||||
}
|
||||
@@ -880,6 +885,8 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
for domain := range m.domainExceptions {
|
||||
if domain == cleanRule || domain == rule {
|
||||
delete(m.domainExceptions, domain)
|
||||
delete(m.domainExceptionsIsLocal, domain)
|
||||
delete(m.domainExceptionsSource, domain)
|
||||
removed = true
|
||||
break
|
||||
}
|
||||
@@ -887,6 +894,36 @@ func (m *ShieldManager) RemoveRule(rule string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// 如果没有删除任何规则,尝试删除可能的子域名规则
|
||||
if !removed {
|
||||
// 解析原始规则,提取可能的主域名
|
||||
originalRule := cleanRule
|
||||
// 移除可能的前缀
|
||||
originalRule = strings.TrimPrefix(originalRule, "@@||")
|
||||
originalRule = strings.TrimPrefix(originalRule, "||")
|
||||
|
||||
// 检查是否有子域名规则需要删除
|
||||
// 遍历所有域名规则,删除包含原始规则作为后缀的子域名规则
|
||||
for domain := range m.domainRules {
|
||||
if strings.HasSuffix(domain, "."+originalRule) || domain == originalRule {
|
||||
delete(m.domainRules, domain)
|
||||
delete(m.domainRulesIsLocal, domain)
|
||||
delete(m.domainRulesSource, domain)
|
||||
removed = true
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历所有排除规则,删除包含原始规则作为后缀的子域名规则
|
||||
for domain := range m.domainExceptions {
|
||||
if strings.HasSuffix(domain, "."+originalRule) || domain == originalRule {
|
||||
delete(m.domainExceptions, domain)
|
||||
delete(m.domainExceptionsIsLocal, domain)
|
||||
delete(m.domainExceptionsSource, domain)
|
||||
removed = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有规则被删除,持久化保存更改
|
||||
if removed && m.config.LocalRulesFile != "" {
|
||||
if err := m.saveRulesToFile(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user