MCPcopy Create free account
hub / github.com/JordanCoin/codemap / buildTreeStructure

Function buildTreeStructure

render/tree.go:64–92  ·  view source on GitHub ↗

buildTreeStructure builds a nested tree from flat file list

(files []scanner.FileInfo)

Source from the content-addressed store, hash-verified

62
63// buildTreeStructure builds a nested tree from flat file list
64func buildTreeStructure(files []scanner.FileInfo) *treeNode {
65 root := &treeNode{children: make(map[string]*treeNode)}
66
67 for _, f := range files {
68 parts := strings.Split(f.Path, string(os.PathSeparator))
69 current := root
70 for i, part := range parts {
71 if i == len(parts)-1 {
72 // File
73 fileCopy := f
74 current.children[part] = &treeNode{
75 name: part,
76 isFile: true,
77 file: &fileCopy,
78 }
79 } else {
80 // Directory
81 if current.children[part] == nil {
82 current.children[part] = &treeNode{
83 name: part,
84 children: make(map[string]*treeNode),
85 }
86 }
87 current = current.children[part]
88 }
89 }
90 }
91 return root
92}
93
94// formatSize converts bytes to human readable format
95func formatSize(size int64) string {

Callers 4

TreeFunction · 0.85
TestBuildTreeStructureFunction · 0.85

Calls

no outgoing calls

Tested by 3

TestBuildTreeStructureFunction · 0.68