mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
fix container size computation: handle hard links
This change makes docker compute container size correctly. The old code isn't taking hard links into account. Containers could seem like they're up to 1-1.5x larger than they really were.
This commit is contained in:
parent
ac821f2446
commit
78c843c8ef
1 changed files with 30 additions and 4 deletions
34
container.go
34
container.go
|
@ -1559,20 +1559,46 @@ func validateID(id string) error {
|
|||
// GetSize, return real size, virtual size
|
||||
func (container *Container) GetSize() (int64, int64) {
|
||||
var sizeRw, sizeRootfs int64
|
||||
data := make(map[uint64]bool)
|
||||
|
||||
filepath.Walk(container.rwPath(), func(path string, fileInfo os.FileInfo, err error) error {
|
||||
if fileInfo != nil {
|
||||
sizeRw += fileInfo.Size()
|
||||
if fileInfo == nil {
|
||||
return nil
|
||||
}
|
||||
size := fileInfo.Size()
|
||||
if size == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
inode := fileInfo.Sys().(*syscall.Stat_t).Ino
|
||||
if _, entryExists := data[inode]; entryExists {
|
||||
return nil
|
||||
}
|
||||
data[inode] = false
|
||||
|
||||
sizeRw += size
|
||||
return nil
|
||||
})
|
||||
|
||||
data = make(map[uint64]bool)
|
||||
_, err := os.Stat(container.RootfsPath())
|
||||
if err == nil {
|
||||
filepath.Walk(container.RootfsPath(), func(path string, fileInfo os.FileInfo, err error) error {
|
||||
if fileInfo != nil {
|
||||
sizeRootfs += fileInfo.Size()
|
||||
if fileInfo == nil {
|
||||
return nil
|
||||
}
|
||||
size := fileInfo.Size()
|
||||
if size == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
inode := fileInfo.Sys().(*syscall.Stat_t).Ino
|
||||
if _, entryExists := data[inode]; entryExists {
|
||||
return nil
|
||||
}
|
||||
data[inode] = false
|
||||
|
||||
sizeRootfs += size
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue