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
|
package doozer
type Visitor interface {
VisitDir(path string, f *FileInfo) bool
VisitFile(path string, f *FileInfo)
}
// Walk walks the file tree in revision rev, rooted at root,
// analogously to Walk in package path/filepath.
func Walk(c *Conn, rev int64, root string, v Visitor, errors chan<- error) {
f, err := c.Statinfo(rev, root)
if err != nil {
if errors != nil {
errors <- err
}
return
}
walk(c, rev, root, f, v, errors)
}
func walk(c *Conn, r int64, path string, f *FileInfo, v Visitor, errors chan<- error) {
if !f.IsDir {
v.VisitFile(path, f)
return
}
if !v.VisitDir(path, f) {
return
}
list, err := c.Getdirinfo(path, r, 0, -1)
if err != nil && errors != nil {
errors <- err
}
if path != "/" {
path += "/"
}
for i := range list {
walk(c, r, path+list[i].Name, &list[i], v, errors)
}
}
|