refractor: rename some path util function.

This commit is contained in:
Alexandre Pujol 2024-10-12 15:31:24 +01:00
parent ebdeef152c
commit 982c2c66aa
No known key found for this signature in database
GPG key ID: C5469996F0DF68EC
13 changed files with 87 additions and 82 deletions

View file

@ -15,7 +15,6 @@ import (
"github.com/roddhjav/apparmor.d/pkg/prebuild/builder"
"github.com/roddhjav/apparmor.d/pkg/prebuild/directive"
"github.com/roddhjav/apparmor.d/pkg/prebuild/prepare"
"github.com/roddhjav/apparmor.d/pkg/util"
)
const (
@ -138,7 +137,7 @@ func Build() error {
if !file.Exist() {
continue
}
profile, err := util.ReadFile(file)
profile, err := file.ReadFileAsString()
if err != nil {
return err
}

View file

@ -13,7 +13,6 @@ import (
"github.com/roddhjav/apparmor.d/pkg/aa"
"github.com/roddhjav/apparmor.d/pkg/prebuild"
"github.com/roddhjav/apparmor.d/pkg/util"
)
type Exec struct {
@ -44,7 +43,7 @@ func (d Exec) Apply(opt *Option, profileRaw string) (string, error) {
rules := aa.Rules{}
for name := range opt.ArgMap {
profiletoTransition := util.MustReadFile(prebuild.RootApparmord.Join(name))
profiletoTransition := prebuild.RootApparmord.Join(name).MustReadFileAsString()
dstProfile := aa.DefaultTunables()
if _, err := dstProfile.Parse(profiletoTransition); err != nil {
return "", err

View file

@ -55,7 +55,7 @@ func (s Stack) Apply(opt *Option, profile string) (string, error) {
res := ""
for name := range opt.ArgMap {
stackedProfile := util.MustReadFile(prebuild.RootApparmord.Join(name))
stackedProfile := prebuild.RootApparmord.Join(name).MustReadFileAsString()
m := regRules.FindStringSubmatch(stackedProfile)
if len(m) < 2 {
return "", fmt.Errorf("No profile found in %s", name)

View file

@ -8,7 +8,6 @@ import (
"strings"
"github.com/roddhjav/apparmor.d/pkg/paths"
"github.com/roddhjav/apparmor.d/pkg/util"
)
// Default content of debian/apparmor.d.hide. Whonix has special addition.
@ -29,7 +28,7 @@ func (f Flagger) Read(name string) map[string][]string {
return res
}
lines := util.MustReadFileAsLines(path)
lines := path.MustReadFilteredFileAsLines()
for _, line := range lines {
manifest := strings.Split(line, " ")
profile := manifest[0]
@ -49,7 +48,7 @@ func (i Ignorer) Read(name string) []string {
if !path.Exist() {
return []string{}
}
return util.MustReadFileAsLines(path)
return path.MustReadFilteredFileAsLines()
}
type DebianHider struct {

View file

@ -10,7 +10,6 @@ import (
"strings"
"github.com/roddhjav/apparmor.d/pkg/prebuild"
"github.com/roddhjav/apparmor.d/pkg/util"
)
var (
@ -44,7 +43,7 @@ func (p SetFlags) Apply() ([]string, error) {
// Overwrite profile flags
if len(flags) > 0 {
flagsStr := " flags=(" + strings.Join(flags, ",") + ") {\n"
out, err := util.ReadFile(file)
out, err := file.ReadFileAsString()
if err != nil {
return res, err
}

View file

@ -35,7 +35,7 @@ func (p FullSystemPolicy) Apply() ([]string, error) {
// Set systemd profile name
path := prebuild.RootApparmord.Join("tunables/multiarch.d/system")
out, err := util.ReadFile(path)
out, err := path.ReadFileAsString()
if err != nil {
return res, err
}
@ -47,7 +47,7 @@ func (p FullSystemPolicy) Apply() ([]string, error) {
// Fix conflicting x modifiers in abstractions - FIXME: Temporary solution
path = prebuild.RootApparmord.Join("abstractions/gstreamer")
out, err = util.ReadFile(path)
out, err = path.ReadFileAsString()
if err != nil {
return res, err
}

View file

@ -9,7 +9,6 @@ import (
"os"
"github.com/roddhjav/apparmor.d/pkg/prebuild"
"github.com/roddhjav/apparmor.d/pkg/util"
)
const ext = ".apparmor.d"
@ -44,7 +43,7 @@ func (p Overwrite) Apply() ([]string, error) {
if !path.Exist() {
return res, fmt.Errorf("%s not found", path)
}
for _, name := range util.MustReadFileAsLines(path) {
for _, name := range path.MustReadFilteredFileAsLines() {
origin := prebuild.RootApparmord.Join(name)
dest := prebuild.RootApparmord.Join(name + ext)
if !dest.Exist() && p.OneFile {