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 { ...@@ -126,31 +126,16 @@ func (f *serialFile) Stat() os.FileInfo {
} }
func (f *serialFile) Size() (int64, error) { func (f *serialFile) Size() (int64, error) {
return size(f.stat, f.FileName()) if !f.stat.IsDir() {
} return f.stat.Size(), nil
func size(stat os.FileInfo, filename string) (int64, error) {
if !stat.IsDir() {
return stat.Size(), nil
} }
file, err := os.Open(filename) var du int64
if err != nil { err := fp.Walk(f.FileName(), func(p string, fi os.FileInfo, err error) error {
return 0, err if fi != nil && fi.Mode()&(os.ModeSymlink|os.ModeNamedPipe) == 0 {
} du += fi.Size()
files, err := file.Readdir(0)
if err != nil {
return 0, err
} }
file.Close() return nil
})
var output int64 return du, err
for _, child := range files {
s, err := size(child, fp.Join(filename, child.Name()))
if err != nil {
return 0, err
}
output += s
}
return output, nil
} }
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