From 179af9eeb6ff0bece7916baeaba7ce8c5300aabe Mon Sep 17 00:00:00 2001 From: Ahmet Alp Balkan Date: Thu, 13 Nov 2014 10:50:57 -0800 Subject: [PATCH] Extract TreeSize to daemon build TreeSize uses syscall.Stat_t which is not available on Windows. It's called only on daemon path, therefore extracting it to daemon with build tag 'daemon' Signed-off-by: Ahmet Alp Balkan Upstream-commit: b64c9b521ab4e4082ed874a23a493f4a266304d5 Component: engine --- .../engine/daemon/graphdriver/fsdiff.go | 2 + components/engine/utils/utils.go | 31 --------------- components/engine/utils/utils_daemon.go | 39 +++++++++++++++++++ 3 files changed, 41 insertions(+), 31 deletions(-) create mode 100644 components/engine/utils/utils_daemon.go diff --git a/components/engine/daemon/graphdriver/fsdiff.go b/components/engine/daemon/graphdriver/fsdiff.go index 269379bddf..3569cf910e 100644 --- a/components/engine/daemon/graphdriver/fsdiff.go +++ b/components/engine/daemon/graphdriver/fsdiff.go @@ -1,3 +1,5 @@ +// +build daemon + package graphdriver import ( diff --git a/components/engine/utils/utils.go b/components/engine/utils/utils.go index e2254b8bab..84d01f6c9d 100644 --- a/components/engine/utils/utils.go +++ b/components/engine/utils/utils.go @@ -18,7 +18,6 @@ import ( "strconv" "strings" "sync" - "syscall" log "github.com/Sirupsen/logrus" "github.com/docker/docker/dockerversion" @@ -453,36 +452,6 @@ func ReadSymlinkedDirectory(path string) (string, error) { return realPath, nil } -// TreeSize walks a directory tree and returns its total size in bytes. -func TreeSize(dir string) (size int64, err error) { - data := make(map[uint64]struct{}) - 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 - } - - // Check inode to handle hard links correctly - inode := fileInfo.Sys().(*syscall.Stat_t).Ino - // inode is not a uint64 on all platforms. Cast it to avoid issues. - if _, exists := data[uint64(inode)]; exists { - return nil - } - // inode is not a uint64 on all platforms. Cast it to avoid issues. - data[uint64(inode)] = struct{}{} - - size += s - - return nil - }) - return -} - // ValidateContextDirectory checks if all the contents of the directory // can be read and returns an error if some files can't be read // symlinks which point to non-existing files don't trigger an error diff --git a/components/engine/utils/utils_daemon.go b/components/engine/utils/utils_daemon.go new file mode 100644 index 0000000000..098e227367 --- /dev/null +++ b/components/engine/utils/utils_daemon.go @@ -0,0 +1,39 @@ +// +build daemon + +package utils + +import ( + "os" + "path/filepath" + "syscall" +) + +// TreeSize walks a directory tree and returns its total size in bytes. +func TreeSize(dir string) (size int64, err error) { + data := make(map[uint64]struct{}) + 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 + } + + // Check inode to handle hard links correctly + inode := fileInfo.Sys().(*syscall.Stat_t).Ino + // inode is not a uint64 on all platforms. Cast it to avoid issues. + if _, exists := data[uint64(inode)]; exists { + return nil + } + // inode is not a uint64 on all platforms. Cast it to avoid issues. + data[uint64(inode)] = struct{}{} + + size += s + + return nil + }) + return +}