mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement fallback for getting the size of a container
This moves Driver.Size() to Differ.DiffSize(), removing the empty implementations in devmapper and dummy, and renaming the one in aufs. Then we fall back to a container.Changes() implementation in the non-aufs case.
This commit is contained in:
parent
e42b574579
commit
5d76681c3d
6 changed files with 35 additions and 18 deletions
|
@ -280,6 +280,20 @@ func ChangesDirs(newDir, oldDir string) ([]Change, error) {
|
|||
return newRoot.Changes(oldRoot), nil
|
||||
}
|
||||
|
||||
func ChangesSize(newDir string, changes []Change) int64 {
|
||||
var size int64
|
||||
for _, change := range changes {
|
||||
if change.Kind == ChangeModify || change.Kind == ChangeAdd {
|
||||
file := filepath.Join(newDir, change.Path)
|
||||
fileInfo, _ := os.Lstat(file)
|
||||
if fileInfo != nil && !fileInfo.IsDir() {
|
||||
size += fileInfo.Size()
|
||||
}
|
||||
}
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
func ExportChanges(dir string, changes []Change) (Archive, error) {
|
||||
files := make([]string, 0)
|
||||
deletions := make([]string, 0)
|
||||
|
|
27
container.go
27
container.go
|
@ -7,6 +7,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/archive"
|
||||
"github.com/dotcloud/docker/graphdriver"
|
||||
"github.com/dotcloud/docker/term"
|
||||
"github.com/dotcloud/docker/utils"
|
||||
"github.com/kr/pty"
|
||||
|
@ -1552,18 +1553,28 @@ func (container *Container) GetSize() (int64, int64) {
|
|||
driver = container.runtime.driver
|
||||
)
|
||||
|
||||
sizeRw, err = driver.Size(container.ID)
|
||||
if err != nil {
|
||||
utils.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err)
|
||||
// FIXME: GetSize should return an error. Not changing it now in case
|
||||
// there is a side-effect.
|
||||
sizeRw = -1
|
||||
}
|
||||
|
||||
if err := container.EnsureMounted(); err != nil {
|
||||
utils.Errorf("Warning: failed to compute size of container rootfs %s: %s", container.ID, err)
|
||||
return sizeRw, sizeRootfs
|
||||
}
|
||||
|
||||
if differ, ok := container.runtime.driver.(graphdriver.Differ); ok {
|
||||
sizeRw, err = differ.DiffSize(container.ID)
|
||||
if err != nil {
|
||||
utils.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err)
|
||||
// FIXME: GetSize should return an error. Not changing it now in case
|
||||
// there is a side-effect.
|
||||
sizeRw = -1
|
||||
}
|
||||
} else {
|
||||
changes, _ := container.Changes()
|
||||
if changes != nil {
|
||||
sizeRw = archive.ChangesSize(container.RootfsPath(), changes)
|
||||
} else {
|
||||
sizeRw = -1
|
||||
}
|
||||
}
|
||||
|
||||
_, err = os.Stat(container.RootfsPath())
|
||||
if err == nil {
|
||||
filepath.Walk(container.RootfsPath(), func(path string, fileInfo os.FileInfo, err error) error {
|
||||
|
|
|
@ -219,7 +219,7 @@ func (a *AufsDriver) ApplyDiff(id string, diff archive.Archive) error {
|
|||
}
|
||||
|
||||
// Returns the size of the contents for the id
|
||||
func (a *AufsDriver) Size(id string) (int64, error) {
|
||||
func (a *AufsDriver) DiffSize(id string) (int64, error) {
|
||||
return utils.TreeSize(path.Join(a.rootPath(), "diff", id))
|
||||
}
|
||||
|
||||
|
|
|
@ -72,10 +72,6 @@ func (d *Driver) Get(id string) (string, error) {
|
|||
return mp, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Size(id string) (int64, error) {
|
||||
return -1, fmt.Errorf("Not implemented")
|
||||
}
|
||||
|
||||
func (d *Driver) mount(id, mountPoint string) error {
|
||||
// Create the target directories if they don't exist
|
||||
if err := os.MkdirAll(mountPoint, 0755); err != nil && !os.IsExist(err) {
|
||||
|
|
|
@ -17,7 +17,6 @@ type Driver interface {
|
|||
Remove(id string) error
|
||||
|
||||
Get(id string) (dir string, err error)
|
||||
Size(id string) (bytes int64, err error)
|
||||
|
||||
Status() [][2]string
|
||||
|
||||
|
@ -28,6 +27,7 @@ type Differ interface {
|
|||
Diff(id string) (archive.Archive, error)
|
||||
Changes(id string) ([]archive.Change, error)
|
||||
ApplyDiff(id string, diff archive.Archive) error
|
||||
DiffSize(id string) (bytes int64, err error)
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -76,7 +76,3 @@ func (d *Driver) Get(id string) (string, error) {
|
|||
}
|
||||
return dir, nil
|
||||
}
|
||||
|
||||
func (d *Driver) Size(id string) (int64, error) {
|
||||
return -1, fmt.Errorf("Not implemented")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue