From 4d1a537433ede2bbc75b0a4817e8121f9e03fd86 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 11 Nov 2013 12:09:26 -0800 Subject: [PATCH] Remove Differ and Changer interfaces Add the methods to the Driver interface to force the drivers to implement the methods --- aufs/aufs.go | 6 +---- container.go | 9 +++++--- devmapper/driver.go | 9 ++++++++ graphdriver/driver.go | 10 ++------- graphdriver/dummy/driver.go | 8 +++++++ runtime.go | 45 ++++--------------------------------- 6 files changed, 30 insertions(+), 57 deletions(-) diff --git a/aufs/aufs.go b/aufs/aufs.go index f47c65e661..6865020a94 100644 --- a/aufs/aufs.go +++ b/aufs/aufs.go @@ -210,11 +210,7 @@ func (a *AufsDriver) Diff(id string) (archive.Archive, error) { // Returns the size of the contents for the id func (a *AufsDriver) DiffSize(id string) (int64, error) { - p, err := a.Get(id) - if err != nil { - return -1, err - } - return utils.TreeSize(p) + return utils.TreeSize(path.Join(a.rootPath(), "diff", id)) } func (a *AufsDriver) Changes(id string) ([]archive.Change, error) { diff --git a/container.go b/container.go index a9dafa9e83..3f471f4d09 100644 --- a/container.go +++ b/container.go @@ -1479,10 +1479,13 @@ func validateID(id string) error { // GetSize, return real size, virtual size func (container *Container) GetSize() (int64, int64) { - var sizeRw, sizeRootfs int64 + var ( + sizeRw, sizeRootfs int64 + err error + driver = container.runtime.driver + ) - driver := container.runtime.driver - sizeRw, err := driver.DiffSize(container.ID) + sizeRw, err = driver.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 diff --git a/devmapper/driver.go b/devmapper/driver.go index c23f5288f2..287c0baec4 100644 --- a/devmapper/driver.go +++ b/devmapper/driver.go @@ -2,6 +2,7 @@ package devmapper import ( "fmt" + "github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/graphdriver" "os" "path" @@ -60,6 +61,14 @@ func (d *Driver) DiffSize(id string) (int64, error) { return -1, fmt.Errorf("Not implemented") } +func (d *Driver) Diff(id string) (archive.Archive, error) { + return nil, fmt.Errorf("Not implemented)") +} + +func (d *Driver) Changes(id string) ([]archive.Change, error) { + return nil, fmt.Errorf("asdlfj)") +} + func (d *Driver) mount(id, mp string) error { // Create the target directories if they don't exist if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) { diff --git a/graphdriver/driver.go b/graphdriver/driver.go index e96f6bfa5e..8014eddc71 100644 --- a/graphdriver/driver.go +++ b/graphdriver/driver.go @@ -17,18 +17,12 @@ type Driver interface { Get(id string) (dir string, err error) DiffSize(id string) (bytes int64, err error) + Diff(id string) (archive.Archive, error) + Changes(id string) ([]archive.Change, error) Cleanup() error } -type Changer interface { - Changes(id string) ([]archive.Change, error) -} - -type Differ interface { - Diff(id string) (archive.Archive, error) -} - var ( // All registred drivers drivers map[string]InitFunc diff --git a/graphdriver/dummy/driver.go b/graphdriver/dummy/driver.go index eb05aacb5d..e25f98416e 100644 --- a/graphdriver/dummy/driver.go +++ b/graphdriver/dummy/driver.go @@ -76,3 +76,11 @@ func (d *Driver) Get(id string) (string, error) { func (d *Driver) DiffSize(id string) (int64, error) { return -1, fmt.Errorf("Not implemented") } + +func (d *Driver) Diff(id string) (archive.Archive, error) { + return nil, fmt.Errorf("Not implemented)") +} + +func (d *Driver) Changes(id string) ([]archive.Change, error) { + return nil, fmt.Errorf("asdlfj)") +} diff --git a/runtime.go b/runtime.go index d8ec2a90d4..bb21d192ec 100644 --- a/runtime.go +++ b/runtime.go @@ -18,7 +18,6 @@ import ( "os" "os/exec" "path" - "path/filepath" "sort" "strings" "time" @@ -734,49 +733,13 @@ func (runtime *Runtime) Unmount(container *Container) error { } func (runtime *Runtime) Changes(container *Container) ([]archive.Change, error) { - if changer, ok := runtime.driver.(graphdriver.Changer); ok { - return changer.Changes(container.ID) - } - cDir, err := runtime.driver.Get(container.ID) - if err != nil { - return nil, fmt.Errorf("Error getting container rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err) - } - initDir, err := runtime.driver.Get(container.ID + "-init") - if err != nil { - return nil, fmt.Errorf("Error getting container init rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err) - } - return archive.ChangesDirs(cDir, initDir) + // FIXME: Remove Changes method from runtime + return runtime.driver.Changes(container.ID) } func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) { - if differ, ok := runtime.driver.(graphdriver.Differ); ok { - return differ.Diff(container.ID) - } - - changes, err := runtime.Changes(container) - if err != nil { - return nil, err - } - - cDir, err := runtime.driver.Get(container.ID) - if err != nil { - return nil, fmt.Errorf("Error getting container rootfs %s from driver %s: %s", container.ID, container.runtime.driver, err) - } - - files := make([]string, 0) - deletions := make([]string, 0) - for _, change := range changes { - if change.Kind == archive.ChangeModify || change.Kind == archive.ChangeAdd { - files = append(files, change.Path) - } - if change.Kind == archive.ChangeDelete { - base := filepath.Base(change.Path) - dir := filepath.Dir(change.Path) - deletions = append(deletions, filepath.Join(dir, ".wh."+base)) - } - } - - return archive.TarFilter(cDir, archive.Uncompressed, files, false, deletions) + // FIXME: Remove Diff method from runtime + return runtime.driver.Diff(container.ID) } func linkLxcStart(root string) error {