Commit 58d93674 authored by rht's avatar rht

Use filepath.Walk to compute serialfile total size

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent 59033650
......@@ -126,31 +126,16 @@ func (f *serialFile) Stat() os.FileInfo {
}
func (f *serialFile) Size() (int64, error) {
return size(f.stat, f.FileName())
}
func size(stat os.FileInfo, filename string) (int64, error) {
if !stat.IsDir() {
return stat.Size(), nil
if !f.stat.IsDir() {
return f.stat.Size(), nil
}
file, err := os.Open(filename)
if err != nil {
return 0, err
}
files, err := file.Readdir(0)
if err != nil {
return 0, err
var du int64
err := fp.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 {
du += fi.Size()
}
file.Close()
var output int64
for _, child := range files {
s, err := size(child, fp.Join(filename, child.Name()))
if err != nil {
return 0, err
}
output += s
}
return output, nil
return nil
})
return du, err
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment