Add tree.Stat()

This commit is contained in:
Alexander Neumann
2015-01-04 20:16:08 +01:00
parent fe231af7fc
commit 2a97e2b08a
2 changed files with 40 additions and 0 deletions
+18
View File
@@ -151,6 +151,24 @@ func (t Tree) Find(name string) (*Node, error) {
return node, err
}
func (t Tree) Stat() Stat {
s := Stat{}
for _, n := range t {
switch n.Type {
case "file":
s.Files++
s.Bytes += n.Size
case "dir":
s.Dirs++
s.Add(n.Tree.Stat())
default:
s.Other++
}
}
return s
}
func (node *Node) fill_extra(path string, fi os.FileInfo) (err error) {
stat, ok := fi.Sys().(*syscall.Stat_t)
if !ok {