2015-03-12 14:16:16 +00:00
|
|
|
// +build windows
|
2015-02-27 18:50:55 +00:00
|
|
|
|
|
|
|
package directory
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2015-08-24 21:07:22 +00:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/docker/docker/pkg/longpath"
|
2015-02-27 18:50:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Size walks a directory tree and returns its total size in bytes.
|
|
|
|
func Size(dir string) (size int64, err error) {
|
2015-08-24 21:07:22 +00:00
|
|
|
fixedPath, err := filepath.Abs(dir)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fixedPath = longpath.AddPrefix(fixedPath)
|
2015-02-27 18:50:55 +00: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
|
|
|
|
}
|