AdGuardHome/internal/configmigrate/v27.go

78 lines
1.2 KiB
Go
Raw Normal View History

package configmigrate
Pull request 1983: 5720-wildcard-ignored-domains Updates #5720. Squashed commit of the following: commit e8093c990f15e2efc496f1a04f87360825e34e96 Merge: df5413eef 28fefaff1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 15:06:33 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit df5413eefeac2c7e34eb725db9e2908b5b2d08cb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 14:49:05 2023 +0300 confmigrate: imp docs commit 1644d99b730cc7f22c9d75b8e990149d3ce5b32a Merge: 9542ee161 1e4517898 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 14:23:42 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit 9542ee1616c1dd4bdb6ec9a2af79a2af3858a7e3 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Sep 5 12:48:48 2023 +0300 all: upd chlog commit 183f84a7f73c7bd33669bd108076f60514ca101e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Sep 1 17:11:31 2023 +0300 all: imp chlog commit a704325352a577a9b6652f011b82180ec3a6e095 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 31 18:59:52 2023 +0300 all: imp code commit fe99c3b883500850399b1feb72c914ab878b3107 Merge: 7f11e9460 0182b9ec1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 31 18:43:09 2023 +0300 Merge branch 'master' into 5720-wildcard-ignored-domains commit 7f11e94609027ed821a125d27a1ffde03f37334a Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 19:57:51 2023 +0300 aghnet: add tests commit f10f9190ce1064a5d03155e8b6bba61db977897b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 18:32:07 2023 +0300 all: add conf migration commit a53c14df129765366966c5230dd53aa29bdd25c5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 30 13:37:30 2023 +0300 all: add ignore engine
2023-09-05 15:13:35 +03:00
// migrateTo27 performs the following changes:
//
// # BEFORE:
// 'querylog':
// 'ignored':
// - '.'
// - # …
// # …
// 'statistics':
// 'ignored':
// - '.'
// - # …
// # …
// # …
//
// # AFTER:
// 'querylog':
// 'ignored':
// - '|.^'
// - # …
// # …
// 'statistics':
// 'ignored':
// - '|.^'
// - # …
// # …
// # …
func migrateTo27(diskConf yobj) (err error) {
diskConf["schema_version"] = 27
keys := []string{"querylog", "statistics"}
for _, k := range keys {
err = replaceDot(diskConf, k)
if err != nil {
return err
}
}
return nil
}
// replaceDot replaces rules blocking root domain "." with AdBlock style syntax
// "|.^".
func replaceDot(diskConf yobj, key string) (err error) {
var obj yobj
var ok bool
obj, ok, err = fieldVal[yobj](diskConf, key)
if err != nil {
return err
} else if !ok {
return nil
}
var ignored yarr
ignored, ok, err = fieldVal[yarr](obj, "ignored")
if err != nil {
return err
} else if !ok {
return nil
}
for i, hostVal := range ignored {
var host string
host, ok = hostVal.(string)
if !ok {
continue
}
if host == "." {
ignored[i] = "|.^"
}
}
return nil
}