Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

files: track relabeling using set instead of slice #1324

Merged
merged 1 commit into from
Mar 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}