mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-11-15 07:54:17 +01:00
build: remove directive text not applied on build.
This commit is contained in:
parent
2aa8986a21
commit
c7fb47e97a
@ -61,6 +61,13 @@ func NewOption(file *paths.Path, match []string) *Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Clean the selected directive from profile.
|
||||
// Useful to remove directive text applied on some condition only
|
||||
func (o *Option) Clean(profile string) string {
|
||||
reg := regexp.MustCompile(`\s*` + Keyword + o.Name + ` .*$`)
|
||||
return reg.ReplaceAllString(profile, "")
|
||||
}
|
||||
|
||||
func RegisterDirective(d Directive) {
|
||||
Directives[d.Name()] = d
|
||||
}
|
||||
|
@ -43,10 +43,10 @@ func filterRuleForUs(opt *Option) bool {
|
||||
|
||||
func filter(only bool, opt *Option, profile string) string {
|
||||
if only && filterRuleForUs(opt) {
|
||||
return profile
|
||||
return opt.Clean(profile)
|
||||
}
|
||||
if !only && !filterRuleForUs(opt) {
|
||||
return profile
|
||||
return opt.Clean(profile)
|
||||
}
|
||||
|
||||
inline := true
|
||||
|
@ -31,7 +31,7 @@ func TestFilterOnly_Apply(t *testing.T) {
|
||||
Raw: " @{bin}/arch-audit rPx, #aa:only apt",
|
||||
},
|
||||
profile: " @{bin}/arch-audit rPx, #aa:only apt",
|
||||
want: " @{bin}/arch-audit rPx, #aa:only apt",
|
||||
want: " @{bin}/arch-audit rPx,",
|
||||
},
|
||||
{
|
||||
name: "paragraph",
|
||||
@ -121,7 +121,7 @@ func TestFilterExclude_Apply(t *testing.T) {
|
||||
Raw: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
|
||||
},
|
||||
profile: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
|
||||
want: " @{bin}/dpkg rPx -> child-dpkg, #aa:exclude debian",
|
||||
want: " @{bin}/dpkg rPx -> child-dpkg,",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
Loading…
Reference in New Issue
Block a user