func (tr *transaction) add(typ jobType, u *Unit, parent *job, required, anchor bool) (err error) {
	log.WithFields(log.Fields{
		"typ":      typ,
		"u":        u,
		"parent":   parent,
		"required": required,
		"anchor":   anchor,
	}).Debug("tr.add")
	// TODO: decide if these checks are necessary to do here,
	// as they are performed by the unit method calls already
	//
	//switch typ {
	//case reload:
	//	if !u.IsReloader() {
	//		return ErrNoReload
	//	}
	//case start:
	//	if !u.CanStart() {}
	//}
	var j *job
	var isNew bool

	if tr.unmerged[u] == nil {
		tr.unmerged[u] = &prospectiveJobs{}
	}

	if anchor {
		if j = tr.unmerged[u].anchored[typ]; j == nil {
			j = newJob(typ, u)
			log.Debugf("Created %s", j)

			tr.unmerged[u].anchored[typ] = j

			isNew = true
		}
	} else {
		if j = tr.unmerged[u].optional[typ]; j == nil {
			j = newJob(typ, u)
			log.Debugf("Created %s", j)

			tr.unmerged[u].optional[typ] = j

			isNew = true
		}
	}

	if parent != nil {
		if required {
			parent.requires.Put(j)
			j.requiredBy.Put(parent)
		} else {
			parent.wants.Put(j)
			j.wantedBy.Put(parent)
		}
	}

	if isNew && typ != stop {
		for _, name := range u.Conflicts() {
			dep, err := u.System.Get(name)
			if err != nil {
				return err
			}

			if err = tr.add(stop, dep, j, true, anchor); err != nil {
				return err
			}
		}

		for _, name := range u.Requires() {
			dep, err := u.System.Get(name)
			if err != nil {
				return err
			}

			if err = tr.add(start, dep, j, true, anchor); err != nil {
				return err
			}
		}

		for _, name := range u.Wants() {
			dep, err := u.System.Get(name)
			if err != nil {
				continue
			}

			tr.add(start, dep, j, false, false)
		}
	}

	return nil
}
// recursively adds jobs to transaction
// tries to load dependencies not already present
recursively adds jobs to transaction
tries to load dependencies not already present
// recursively adds jobs to transaction // tries to load dependencies not already present
func (tr *transaction) add(typ jobType, u *Unit, parent *job, required, anchor bool) (err error) {
	log.WithFields(log.Fields{
		"typ":      typ,
		"u":        u,
		"parent":   parent,
		"required": required,
		"anchor":   anchor,
	}).Debug("tr.add")
	switch typ {
	case reload:
		if !u.IsReloader() {
			return ErrNoReload
		}
	case start:
		if !u.CanStart() {}
	}
	var j *job
	var isNew bool
	if tr.unmerged[u] == nil {
		tr.unmerged[u] = &prospectiveJobs{}
	}
	if anchor {
		if j = tr.unmerged[u].anchored[typ]; j == nil {
			j = newJob(typ, u)
			log.Debugf("Created %s", j)
			tr.unmerged[u].anchored[typ] = j
			isNew = true
		}
	} else {
		if j = tr.unmerged[u].optional[typ]; j == nil {
			j = newJob(typ, u)
			log.Debugf("Created %s", j)
			tr.unmerged[u].optional[typ] = j
			isNew = true
		}
	}
	if parent != nil {
		if required {
			parent.requires.Put(j)
			j.requiredBy.Put(parent)
		} else {
			parent.wants.Put(j)
			j.wantedBy.Put(parent)
		}
	}
	if isNew && typ != stop {
		for _, name := range u.Conflicts() {
			dep, err := u.System.Get(name)
			if err != nil {
				return err
			}
			if err = tr.add(stop, dep, j, true, anchor); err != nil {
				return err
			}
		}
		for _, name := range u.Requires() {
			dep, err := u.System.Get(name)
			if err != nil {
				return err
			}
			if err = tr.add(start, dep, j, true, anchor); err != nil {
				return err
			}
		}
		for _, name := range u.Wants() {
			dep, err := u.System.Get(name)
			if err != nil {
				continue
			}
			tr.add(start, dep, j, false, false)
		}
	}
	return nil
}
func ( tr * transaction ) add ( typ jobType , u * Unit , parent * job , required , anchor bool ) ( err error ) { log . WithFields ( log . Fields { " " : typ , " " : u , " " : parent , " " : required , " " : anchor , } ) . Debug ( " " ) var j * job var isNew bool if tr . unmerged [ u ] == nil { tr . unmerged [ u ] = & prospectiveJobs { } } if anchor { if j = tr . unmerged [ u ] . anchored [ typ ] ; j == nil { j = newJob ( typ , u ) log . Debugf ( " " , j ) tr . unmerged [ u ] . anchored [ typ ] = j isNew = true } } else { if j = tr . unmerged [ u ] . optional [ typ ] ; j == nil { j = newJob ( typ , u ) log . Debugf ( " " , j ) tr . unmerged [ u ] . optional [ typ ] = j isNew = true } } if parent != nil { if required { parent . requires . Put ( j ) j . requiredBy . Put ( parent ) } else { parent . wants . Put ( j ) j . wantedBy . Put ( parent ) } } if isNew && typ != stop { for _ , name := range u . Conflicts ( ) { dep , err := u . System . Get ( name ) if err != nil { return err } if err = tr . add ( stop , dep , j , true , anchor ) ; err != nil { return err } } for _ , name := range u . Requires ( ) { dep , err := u . System . Get ( name ) if err != nil { return err } if err = tr . add ( start , dep , j , true , anchor ) ; err != nil { return err } } for _ , name := range u . Wants ( ) { dep , err := u . System . Get ( name ) if err != nil { continue } tr . add ( start , dep , j , false , false ) } } return nil }
recursively adds jobs to transaction
tries to load dependencies not already present
recursively adds jobs to transaction tries to load dependencies not already present
// TODO: decide if these checks are necessary to do here, // as they are performed by the unit method calls already // //switch typ { //case reload: //	if !u.IsReloader() { //		return ErrNoReload //	} //case start: //	if !u.CanStart() {} //}