mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-10-22 01:38:11 +00:00
Doh, this wasn't a proper tree
This commit is contained in:
@@ -14,6 +14,8 @@
|
|||||||
|
|
||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
// ProcStore persists process information to storage.
|
// ProcStore persists process information to storage.
|
||||||
type ProcStore interface {
|
type ProcStore interface {
|
||||||
ProcLoad(int64) (*Proc, error)
|
ProcLoad(int64) (*Proc, error)
|
||||||
@@ -57,18 +59,24 @@ func (p *Proc) Failing() bool {
|
|||||||
|
|
||||||
// Tree creates a process tree from a flat process list.
|
// Tree creates a process tree from a flat process list.
|
||||||
func Tree(procs []*Proc) []*Proc {
|
func Tree(procs []*Proc) []*Proc {
|
||||||
var (
|
var nodes []*Proc
|
||||||
nodes []*Proc
|
|
||||||
parent *Proc
|
|
||||||
)
|
|
||||||
for _, proc := range procs {
|
for _, proc := range procs {
|
||||||
if proc.PPID == 0 {
|
if proc.PPID == 0 {
|
||||||
nodes = append(nodes, proc)
|
nodes = append(nodes, proc)
|
||||||
parent = proc
|
|
||||||
continue
|
|
||||||
} else {
|
} else {
|
||||||
|
parent, _ := findNode(nodes, proc.PPID)
|
||||||
parent.Children = append(parent.Children, proc)
|
parent.Children = append(parent.Children, proc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nodes
|
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")
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user