From dd1bc49c4617ba18e76cca25f8123f4d64cac14d Mon Sep 17 00:00:00 2001 From: Nemric <56299157+Nemric@users.noreply.github.com> Date: Wed, 2 Mar 2022 22:08:53 +0000 Subject: [PATCH] Handling multiple relabelling --- internal/exec/stages/files/files.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/exec/stages/files/files.go b/internal/exec/stages/files/files.go index 6e574531ac..937d97a468 100644 --- a/internal/exec/stages/files/files.go +++ b/internal/exec/stages/files/files.go @@ -59,7 +59,7 @@ func (creator) Name() string { type stage struct { util.Util - toRelabel []string + toRelabel map[string]struct{} } func (stage) Name() string { @@ -132,7 +132,7 @@ func (s *stage) checkRelabeling() error { // initialize to non-nil (whereas a nil slice means not to append, even // though they're functionally equivalent) - s.toRelabel = []string{} + s.toRelabel = make(map[string]struct{}) return nil } @@ -145,7 +145,7 @@ func (s *stage) relabeling() bool { func (s *stage) relabel(paths ...string) { if s.toRelabel != nil { for _, path := range paths { - s.toRelabel = append(s.toRelabel, filepath.Join(s.DestDir, path)) + s.toRelabel[filepath.Join(s.DestDir, path)] = struct{}{} } } } @@ -163,5 +163,9 @@ func (s *stage) relabelFiles() error { // loaded and hence no MAC enforced, and (2) we'd still need after-the-fact // labeling for files created by processes we call out to, like `useradd`. - return s.RelabelFiles(s.toRelabel) + keys := []string{} + for key := range s.toRelabel { + keys = append(keys, key) + } + return s.RelabelFiles(keys) }