forked from someonegg/pathfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge_test.go
More file actions
66 lines (57 loc) · 1.31 KB
/
bridge_test.go
File metadata and controls
66 lines (57 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package pathfs
import "fmt"
func newTestBridge() *rawBridge {
b := &rawBridge{
fs: DefaultFileSystem(),
root: newInode(1, true),
nodeCountHigh: 1,
}
b.nodes = map[uint64]*inode{1: b.root}
b.root.lookupCount = 1
b.nodeCountHigh = 1
b.files = []*fileEntry{{}}
return b
}
// print the directory tree in the format like "tree" command
func printDirTree(root *inode) {
var lastInLevel []bool
printBranch := func(level int, last bool, node *inode) {
prefix := make([]rune, level*3)
for i := 0; i < level; i++ {
if lastInLevel[i] {
prefix[3*i] = ' '
} else {
prefix[3*i] = '│'
}
prefix[3*i+1] = ' '
prefix[3*i+2] = ' '
}
var symbol string
if last {
symbol = "└─ "
} else {
symbol = "├─ "
}
fmt.Printf("%s%s%s(%d)\n", string(prefix), symbol, node.parents.newest.name, node.ino)
}
var walk func(node *inode, level int)
walk = func(node *inode, level int) {
if level >= len(lastInLevel) {
lastInLevel = append(lastInLevel, false)
}
last := false
cnt := 0
for _, child := range node.children {
cnt++
last = cnt == len(node.children)
lastInLevel[level] = last
printBranch(level, last, child)
// is dir
if child.children != nil {
walk(child, level+1)
}
}
}
fmt.Printf(".(%d)\n", root.ino)
walk(root, 0)
}