2015-03-12 10:16:16 -04:00
|
|
|
// +build windows
|
2015-02-27 13:50:55 -05:00
|
|
|
|
|
|
|
package directory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-08-24 17:07:22 -04:00
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/longpath"
|
2015-02-27 13:50:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Size walks a directory tree and returns its total size in bytes.
|
|
|
|
func Size(dir string) (size int64, err error) {
|
2015-08-24 17:07:22 -04:00
|
|
|
fixedPath, err := filepath.Abs(dir)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fixedPath = longpath.AddPrefix(fixedPath)
|
2015-02-27 13:50:55 -05:00
|
|
|
err = filepath.Walk(dir, func(d string, fileInfo os.FileInfo, e error) error {
|
|
|
|
// Ignore directory sizes
|
|
|
|
if fileInfo == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
s := fileInfo.Size()
|
|
|
|
if fileInfo.IsDir() || s == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
size += s
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|