build: use new internal structure.

This commit is contained in:
Alexandre Pujol 2024-03-26 18:07:48 +00:00
parent c8512bc2c6
commit 0f1f9ce49b
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
4 changed files with 13 additions and 34 deletions

View file

@ -32,27 +32,17 @@ func init() {
func (p SetFlags) Apply() ([]string, error) {
res := []string{}
for _, name := range []string{"main.flags", cfg.Distribution + ".flags"} {
path := cfg.FlagDir.Join(name)
if !path.Exist() {
continue
}
lines, _ := path.ReadFileAsLines()
for _, line := range lines {
if strings.HasPrefix(line, "#") || line == "" {
continue
}
manifest := strings.Split(line, " ")
profile := manifest[0]
for _, name := range []string{"main", cfg.Distribution} {
for profile, flags := range cfg.Flags.Read(name) {
file := cfg.RootApparmord.Join(profile)
if !file.Exist() {
res = append(res, fmt.Sprintf("Profile %s not found, ignoring", profile))
continue
}
// If flags is set, overwrite profile flag
if len(manifest) > 1 {
flags := " flags=(" + manifest[1] + ") {"
// Overwrite profile flags
if len(flags) > 0 {
flagsStr := " flags=(" + strings.Join(flags, ",") + ") {"
content, err := file.ReadFile()
if err != nil {
return res, err
@ -60,13 +50,13 @@ func (p SetFlags) Apply() ([]string, error) {
// Remove all flags definition, then set manifest' flags
out := regFlags.ReplaceAllLiteralString(string(content), "")
out = regProfileHeader.ReplaceAllLiteralString(out, flags)
out = regProfileHeader.ReplaceAllLiteralString(out, flagsStr)
if err := file.WriteFile([]byte(out)); err != nil {
return res, err
}
}
}
res = append(res, path.String())
res = append(res, cfg.FlagDir.Join(name+".flags").String())
}
return res, nil
}