mirror of
https://github.com/roddhjav/apparmor.d.git
synced 2024-12-25 06:27:49 +01:00
refractor: move CopyTo
Will be replaced by os.CopyFS with go 1.23
This commit is contained in:
parent
982c2c66aa
commit
e90ccd214c
5 changed files with 9 additions and 53 deletions
|
@ -7,8 +7,8 @@ package prepare
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||
)
|
||||
|
||||
type Configure struct {
|
||||
|
@ -36,7 +36,7 @@ func (p Configure) Apply() ([]string, error) {
|
|||
}
|
||||
|
||||
if prebuild.ABI == 3 {
|
||||
if err := util.CopyTo(prebuild.DistDir.Join("ubuntu"), prebuild.RootApparmord); err != nil {
|
||||
if err := paths.CopyTo(prebuild.DistDir.Join("ubuntu"), prebuild.RootApparmord); err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ func (p Configure) Apply() ([]string, error) {
|
|||
}
|
||||
|
||||
// Copy Debian specific abstractions
|
||||
if err := util.CopyTo(prebuild.DistDir.Join("ubuntu"), prebuild.RootApparmord); err != nil {
|
||||
if err := paths.CopyTo(prebuild.DistDir.Join("ubuntu"), prebuild.RootApparmord); err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ func (p FullSystemPolicy) Apply() ([]string, error) {
|
|||
res := []string{}
|
||||
|
||||
// Install full system policy profiles
|
||||
if err := util.CopyTo(paths.New("apparmor.d/groups/_full/"), prebuild.Root.Join("apparmor.d")); err != nil {
|
||||
if err := paths.CopyTo(paths.New("apparmor.d/groups/_full/"), prebuild.Root.Join("apparmor.d")); err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
|
@ -58,5 +58,5 @@ func (p FullSystemPolicy) Apply() ([]string, error) {
|
|||
}
|
||||
|
||||
// Set systemd unit drop-in files
|
||||
return res, util.CopyTo(prebuild.SystemdDir.Join("full"), prebuild.Root.Join("systemd"))
|
||||
return res, paths.CopyTo(prebuild.SystemdDir.Join("full"), prebuild.Root.Join("systemd"))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ package prepare
|
|||
import (
|
||||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||
)
|
||||
|
||||
type Synchronise struct {
|
||||
|
@ -35,7 +34,7 @@ func (p Synchronise) Apply() ([]string, error) {
|
|||
}
|
||||
if p.Path == "" {
|
||||
for _, name := range []string{"apparmor.d", "share"} {
|
||||
if err := util.CopyTo(paths.New(name), prebuild.Root.Join(name)); err != nil {
|
||||
if err := paths.CopyTo(paths.New(name), prebuild.Root.Join(name)); err != nil {
|
||||
return res, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
package prepare
|
||||
|
||||
import (
|
||||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||
"github.com/roddhjav/apparmor.d/pkg/prebuild"
|
||||
"github.com/roddhjav/apparmor.d/pkg/util"
|
||||
)
|
||||
|
||||
type SystemdDefault struct {
|
||||
|
@ -33,9 +33,9 @@ func init() {
|
|||
}
|
||||
|
||||
func (p SystemdDefault) Apply() ([]string, error) {
|
||||
return []string{}, util.CopyTo(prebuild.SystemdDir.Join("default"), prebuild.Root.Join("systemd"))
|
||||
return []string{}, paths.CopyTo(prebuild.SystemdDir.Join("default"), prebuild.Root.Join("systemd"))
|
||||
}
|
||||
|
||||
func (p SystemdEarly) Apply() ([]string, error) {
|
||||
return []string{}, util.CopyTo(prebuild.SystemdDir.Join("early"), prebuild.Root.Join("systemd"))
|
||||
return []string{}, paths.CopyTo(prebuild.SystemdDir.Join("early"), prebuild.Root.Join("systemd"))
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/roddhjav/apparmor.d/pkg/paths"
|
||||
)
|
||||
|
||||
func TestDecodeHexInString(t *testing.T) {
|
||||
|
@ -90,47 +88,6 @@ func TestRegexReplList_Replace(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestCopyTo(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
src *paths.Path
|
||||
dst *paths.Path
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "default",
|
||||
src: paths.New("../../apparmor.d/groups/_full/"),
|
||||
dst: paths.New("/tmp/test/apparmor.d/groups/_full/"),
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "issue-source",
|
||||
src: paths.New("../../apparmor.d/groups/nope/"),
|
||||
dst: paths.New("/tmp/test/apparmor.d/groups/_full/"),
|
||||
wantErr: true,
|
||||
},
|
||||
// {
|
||||
// name: "issue-dest-1",
|
||||
// src: paths.New("../../apparmor.d/groups/_full/"),
|
||||
// dst: paths.New("/"),
|
||||
// wantErr: true,
|
||||
// },
|
||||
// {
|
||||
// name: "issue-dest-2",
|
||||
// src: paths.New("../../apparmor.d/groups/_full/"),
|
||||
// dst: paths.New("/_full/"),
|
||||
// wantErr: true,
|
||||
// },
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if err := CopyTo(tt.src, tt.dst); (err != nil) != tt.wantErr {
|
||||
t.Errorf("CopyTo() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Filter(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
|
Loading…
Reference in a new issue