mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 10:07:21 +02:00
Doh, this wasn't a proper tree
This commit is contained in:
parent
105a0708fe
commit
3f9356c6a7
@ -14,6 +14,8 @@
|
||||
|
||||
package model
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ProcStore persists process information to storage.
|
||||
type ProcStore interface {
|
||||
ProcLoad(int64) (*Proc, error)
|
||||
@ -57,18 +59,24 @@ func (p *Proc) Failing() bool {
|
||||
|
||||
// Tree creates a process tree from a flat process list.
|
||||
func Tree(procs []*Proc) []*Proc {
|
||||
var (
|
||||
nodes []*Proc
|
||||
parent *Proc
|
||||
)
|
||||
var nodes []*Proc
|
||||
for _, proc := range procs {
|
||||
if proc.PPID == 0 {
|
||||
nodes = append(nodes, proc)
|
||||
parent = proc
|
||||
continue
|
||||
} else {
|
||||
parent, _ := findNode(nodes, proc.PPID)
|
||||
parent.Children = append(parent.Children, proc)
|
||||
}
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
func findNode(nodes []*Proc, pid int) (*Proc, error) {
|
||||
for _, node := range nodes {
|
||||
if node.PID == pid {
|
||||
return node, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("Corrupt proc structure")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user