Skip to content

Commit

Permalink
Merge pull request #1324 from Nemric/Relabeling
Browse files Browse the repository at this point in the history
  • Loading branch information
jlebon committed Mar 4, 2022
2 parents d554570 + e517740 commit 8cb3a69
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions internal/exec/stages/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (creator) Name() string {

type stage struct {
util.Util
toRelabel []string
toRelabel map[string]struct{}
}

func (stage) Name() string {
Expand Down Expand Up @@ -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
}

Expand All @@ -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{}{}
}
}
}
Expand All @@ -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)
}

0 comments on commit 8cb3a69

Please sign in to comment.