mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-25 06:25:44 +03:00
355cec1d7b
Squashed commit of the following:
commit 6e0e61ec2e95a563b04a622f46c6bbe2b2e12711
Merge: e3cccc01a 5b5b39713
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 20:51:29 2024 +0300
Merge branch 'master' into AG-32257-file-permission-mitigation
commit e3cccc01a9cbd382cec0fcd7f3685e43acb48424
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 19:57:32 2024 +0300
dnsforward: imp test
commit 16ecebbc2fd2f4afe2bf475774af1786fa7a02c0
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 19:22:10 2024 +0300
configmigrate: imp tests
commit da8777c3a7c81e17c0d08cfff4e3a9c8d2bbd649
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 18:58:46 2024 +0300
all: imp types, tests
commit 58822a0ef8aa2d944a667d1ba77fe23ff52af424
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 18:28:37 2024 +0300
all: imp chlog
commit 8ce81f918cc5cf43972e2045532a48c829257a2f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Wed Oct 2 18:09:57 2024 +0300
all: improve permissions, add safe_fs_patterns
63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package configmigrate
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
)
|
|
|
|
// migrateTo29 performs the following changes:
|
|
//
|
|
// # BEFORE:
|
|
// 'filters':
|
|
// - 'enabled': true
|
|
// 'url': /path/to/file.txt
|
|
// 'name': My FS Filter
|
|
// 'id': 1234
|
|
//
|
|
// # AFTER:
|
|
// 'filters':
|
|
// - 'enabled': true
|
|
// 'url': /path/to/file.txt
|
|
// 'name': My FS Filter
|
|
// 'id': 1234
|
|
// # …
|
|
// 'filtering':
|
|
// 'safe_fs_patterns':
|
|
// - '/opt/AdGuardHome/data/userfilters/*'
|
|
// - '/path/to/file.txt'
|
|
// # …
|
|
func (m Migrator) migrateTo29(diskConf yobj) (err error) {
|
|
diskConf["schema_version"] = 29
|
|
|
|
filterVals, ok, err := fieldVal[[]any](diskConf, "filters")
|
|
if !ok {
|
|
return err
|
|
}
|
|
|
|
paths := []string{
|
|
filepath.Join(m.dataDir, "userfilters", "*"),
|
|
}
|
|
|
|
for i, v := range filterVals {
|
|
var f yobj
|
|
f, ok = v.(yobj)
|
|
if !ok {
|
|
return fmt.Errorf("filters: at index %d: expected object, got %T", i, v)
|
|
}
|
|
|
|
var u string
|
|
u, ok, _ = fieldVal[string](f, "url")
|
|
if ok && filepath.IsAbs(u) {
|
|
paths = append(paths, u)
|
|
}
|
|
}
|
|
|
|
fltConf, ok, err := fieldVal[yobj](diskConf, "filtering")
|
|
if !ok {
|
|
return err
|
|
}
|
|
|
|
fltConf["safe_fs_patterns"] = paths
|
|
|
|
return nil
|
|
}
|