Factor out writeDropins to reduce complexity
This reduces cyclomatic complexity so that the linter won't fail when
more changes are made to writeUnits
@@ -1430,12 +1430,8 @@ func (dn *Daemon) presetUnit(unit ign3types.Unit) error {
return nil
}
-// writeUnits writes the systemd units to disk
-func (dn *Daemon) writeUnits(units []ign3types.Unit) error {
- var enabledUnits []string
- var disabledUnits []string
- for _, u := range units {
- // write the dropin to disk
+// write dropins to disk
+func (dn *Daemon) writeDropins(u ign3types.Unit) error {
for i := range u.Dropins {
dpath := filepath.Join(pathSystemd, u.Name+".d", u.Dropins[i].Name)
if u.Dropins[i].Contents == nil || *u.Dropins[i].Contents == "" {
@@ -1466,6 +1462,17 @@ func (dn *Daemon) writeUnits(units []ign3types.Unit) error {
glog.V(2).Infof("Wrote systemd unit dropin at %s", dpath)
}
+ return nil
+}
+
+// writeUnits writes the systemd units to disk
+func (dn *Daemon) writeUnits(units []ign3types.Unit) error {
+ var enabledUnits []string
+ var disabledUnits []string
+ for _, u := range units {
+ if err := dn.writeDropins(u); err != nil {
+ return err
+ }
fpath := filepath.Join(pathSystemd, u.Name)
