"log"
"os"
"os/user"
+ "reflect"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
// If the protector is on a different filesystem, we need to add a link
// to it on the policy's filesystem.
- if policy.Context.Mount != protector.Context.Mount {
+ if !reflect.DeepEqual(policy.Context.Mount, protector.Context.Mount) {
log.Printf("policy on %s\n protector on %s\n", policy.Context.Mount, protector.Context.Mount)
ownerIfCreating, err := getOwnerOfMetadataForProtector(protector)
if err != nil {
func (policy *Policy) Apply(path string) error {
if pathMount, err := filesystem.FindMount(path); err != nil {
return err
- } else if pathMount != policy.Context.Mount {
+ } else if !reflect.DeepEqual(pathMount, policy.Context.Mount) {
return &ErrDifferentFilesystem{policy.Context.Mount, pathMount}
}
"fmt"
"os"
"path/filepath"
+ "reflect"
"strings"
"testing"
)
}
}
}
+
+// Test mount comparison by values instead of by reference,
+// as the map mountsByDevice gets recreated on each load.
+// This ensures that concurrent mounts work properly.
+func TestMountComparison(t *testing.T) {
+ var mountinfo = `
+15 0 259:3 / /home rw,relatime shared:1 - ext4 /dev/root rw,data=ordered
+`
+ beginLoadMountInfoTest()
+ defer endLoadMountInfoTest()
+ loadMountInfoFromString(mountinfo)
+ firstMnt := mountForDevice("259:3")
+ loadMountInfoFromString(mountinfo)
+ secondMnt := mountForDevice("259:3")
+ if !reflect.DeepEqual(firstMnt, secondMnt) {
+ t.Errorf("Mount comparison does not work")
+ }
+}