Skip to content

Commit

Permalink
Fix jenkins error on relabeled preset paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemric committed Feb 4, 2022
1 parent a07c88b commit 9690da8
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions internal/exec/stages/files/units.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package files
import (
"fmt"
"path/filepath"
"sort"
"strings"

"github.com/coreos/ignition/v2/config/shared/errors"
Expand Down Expand Up @@ -158,6 +157,20 @@ func parseInstanceUnit(unit types.Unit) (string, string, error) {
// createSystemdPresetFile creates the presetfile for enabled/disabled
// systemd units.
func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error {

//getting directories from presets file for relabling
paths := make(map[string]bool)
for _, preset := range presets {
path := filepath.Dir(s.SystemdPresetPath(preset.scope))
if _, value := paths[path]; !value {
paths[path] = false
if err := s.relabelPath(filepath.Join(s.DestDir, path)); err != nil {
return err
}
paths[path] = true
}
}

hasInstanceUnit := false
for _, preset := range presets {
unitString := preset.unit
Expand Down Expand Up @@ -193,25 +206,6 @@ func (s *stage) createSystemdPresetFiles(presets map[string]*Preset) error {
}
}

//getting all paths from presets
var paths []string
for _, preset := range presets {
paths = append(paths, s.SystemdPresetPath(preset.scope))
}
sort.Slice(paths, func(i, j int) bool {
return paths[i] < paths[j]
})
//running accros differents paths not to apply them s.relabalpath more than once
var tmppath string = ""
for _, path := range paths {
if path != tmppath {
if err := s.relabelPath(filepath.Join(s.DestDir, path)); err != nil {
return err
}
}
tmppath = path
}

return nil
}

Expand Down

0 comments on commit 9690da8

Please sign in to comment.