buildTreeStructure builds a nested tree from flat file list
(files []scanner.FileInfo)
| 62 | |
| 63 | // buildTreeStructure builds a nested tree from flat file list |
| 64 | func 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 |
| 95 | func formatSize(size int64) string { |
no outgoing calls