From e5177407c64d22dd18845bfc9c1baf69cc6e60f0 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] files: track relabeling using set instead of slice That way we avoid passing the same path to `setfiles` multiple times. --- internal/exec/stages/files/files.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/exec/stages/files/files.go b/internal/exec/stages/files/files.go index 6e574531a..7d97df5fe 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 { @@ -130,9 +130,9 @@ func (s *stage) checkRelabeling() error { return nil } - // initialize to non-nil (whereas a nil slice means not to append, even + // initialize to non-nil (whereas a nil map 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 := make([]string, 0, len(s.toRelabel)) + for key := range s.toRelabel { + keys = append(keys, key) + } + return s.RelabelFiles(keys) }