build: make synchronise task configurable.

Required by downtream repository.
This commit is contained in:
Alexandre Pujol 2025-01-14 23:57:19 +01:00
parent f1182b27bb
commit 9953cf1fbd
Failed to generate hash of commit
2 changed files with 25 additions and 24 deletions

View file

@ -99,7 +99,7 @@ func Configure() {
if file != "" {
sync, _ := prepare.Tasks["synchronise"].(*prepare.Synchronise)
sync.Path = file
sync.Paths = []string{file}
overwrite, _ := prepare.Tasks["overwrite"].(*prepare.Overwrite)
overwrite.OneFile = true
}

View file

@ -11,7 +11,7 @@ import (
type Synchronise struct {
prebuild.Base
Path string
Paths []string // File or directory to sync into the build directory.
}
func init() {
@ -20,38 +20,39 @@ func init() {
Keyword: "synchronise",
Msg: "Initialize a new clean apparmor.d build directory",
},
Path: "",
Paths: []string{"apparmor.d", "share"},
})
}
func (p Synchronise) Apply() ([]string, error) {
res := []string{}
dirs := paths.PathList{prebuild.RootApparmord, prebuild.Root.Join("share"), prebuild.Root.Join("systemd")}
for _, dir := range dirs {
if err := dir.RemoveAll(); err != nil {
if err := prebuild.Root.Join("systemd").RemoveAll(); err != nil {
return res, err
}
}
if p.Path == "" {
for _, name := range []string{"apparmor.d", "share"} {
if err := paths.CopyTo(paths.New(name), prebuild.Root.Join(name)); err != nil {
if err := prebuild.RootApparmord.RemoveAll(); err != nil {
return res, err
}
for _, name := range p.Paths {
src := paths.New(name)
dst := prebuild.Root.Join(name)
if err := dst.RemoveAll(); err != nil {
return res, err
}
if src.IsDir() {
if err := paths.CopyTo(src, dst); err != nil {
return res, err
}
} else {
file := paths.New(p.Path)
destination, err := file.RelFrom(paths.New("apparmor.d"))
if err != nil {
if err := dst.Parent().MkdirAll(); err != nil {
return res, err
}
destination = prebuild.RootApparmord.JoinPath(destination)
if err := destination.Parent().MkdirAll(); err != nil {
if err := src.CopyTo(dst); err != nil {
return res, err
}
if err := file.CopyTo(destination); err != nil {
return res, err
}
res = append(res, destination.String())
res = append(res, dst.String())
}
return res, nil
}