buildTree constructs a tree structure from flat file paths.
(files []discovery.SkillFile)
| 498 | |
| 499 | // buildTree constructs a tree structure from flat file paths. |
| 500 | func buildTree(files []discovery.SkillFile) *treeNode { |
| 501 | root := &treeNode{isDir: true} |
| 502 | for _, f := range files { |
| 503 | parts := strings.Split(f.Path, "/") |
| 504 | current := root |
| 505 | for i, part := range parts { |
| 506 | isLast := i == len(parts)-1 |
| 507 | found := false |
| 508 | for _, child := range current.children { |
| 509 | if child.name == part { |
| 510 | current = child |
| 511 | found = true |
| 512 | break |
| 513 | } |
| 514 | } |
| 515 | if !found { |
| 516 | node := &treeNode{name: part, isDir: !isLast} |
| 517 | current.children = append(current.children, node) |
| 518 | current = node |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | sortTree(root) |
| 523 | return root |
| 524 | } |
| 525 | |
| 526 | func sortTree(node *treeNode) { |
| 527 | sort.Slice(node.children, func(i, j int) bool { |