Adjust callback to support continuing or stopping at current depth

This commit is contained in:
Dane Everitt
2020-04-18 18:51:19 -07:00
parent 9dcf06d106
commit 3bca54655b
3 changed files with 19 additions and 6 deletions

View File

@@ -155,8 +155,13 @@ func (fs *Filesystem) DirectorySize(dir string) (int64, error) {
ctx := context.Background()
var size int64
err := w.Walk(dir, ctx, func(f os.FileInfo) {
atomic.AddInt64(&size, f.Size())
err := w.Walk(dir, ctx, func(f os.FileInfo) bool {
// Only increment the size when we're dealing with a file specifically, otherwise
// just continue digging deeper until there are no more directories to iterate over.
if !f.IsDir() {
atomic.AddInt64(&size, f.Size())
}
return true
})
return size, err