Remove Differ and Changer interfaces

Add the methods to the Driver interface
to force the drivers to implement the methods
This commit is contained in:
Michael Crosby 2013-11-11 12:09:26 -08:00
parent ec6fe9f200
commit 4d1a537433
6 changed files with 30 additions and 57 deletions

View file

@ -210,11 +210,7 @@ func (a *AufsDriver) Diff(id string) (archive.Archive, error) {
// Returns the size of the contents for the id // Returns the size of the contents for the id
func (a *AufsDriver) DiffSize(id string) (int64, error) { func (a *AufsDriver) DiffSize(id string) (int64, error) {
p, err := a.Get(id) return utils.TreeSize(path.Join(a.rootPath(), "diff", id))
if err != nil {
return -1, err
}
return utils.TreeSize(p)
} }
func (a *AufsDriver) Changes(id string) ([]archive.Change, error) { func (a *AufsDriver) Changes(id string) ([]archive.Change, error) {

View file

@ -1479,10 +1479,13 @@ func validateID(id string) error {
// GetSize, return real size, virtual size // GetSize, return real size, virtual size
func (container *Container) GetSize() (int64, int64) { 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 { if err != nil {
utils.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err) 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 // FIXME: GetSize should return an error. Not changing it now in case

View file

@ -2,6 +2,7 @@ package devmapper
import ( import (
"fmt" "fmt"
"github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/graphdriver" "github.com/dotcloud/docker/graphdriver"
"os" "os"
"path" "path"
@ -60,6 +61,14 @@ func (d *Driver) DiffSize(id string) (int64, error) {
return -1, fmt.Errorf("Not implemented") 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 { func (d *Driver) mount(id, mp string) error {
// Create the target directories if they don't exist // Create the target directories if they don't exist
if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) { if err := os.MkdirAll(mp, 0755); err != nil && !os.IsExist(err) {

View file

@ -17,18 +17,12 @@ type Driver interface {
Get(id string) (dir string, err error) Get(id string) (dir string, err error)
DiffSize(id string) (bytes int64, err error) DiffSize(id string) (bytes int64, err error)
Diff(id string) (archive.Archive, error)
Changes(id string) ([]archive.Change, error)
Cleanup() error Cleanup() error
} }
type Changer interface {
Changes(id string) ([]archive.Change, error)
}
type Differ interface {
Diff(id string) (archive.Archive, error)
}
var ( var (
// All registred drivers // All registred drivers
drivers map[string]InitFunc drivers map[string]InitFunc

View file

@ -76,3 +76,11 @@ func (d *Driver) Get(id string) (string, error) {
func (d *Driver) DiffSize(id string) (int64, error) { func (d *Driver) DiffSize(id string) (int64, error) {
return -1, fmt.Errorf("Not implemented") 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)")
}

View file

@ -18,7 +18,6 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"path/filepath"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -734,49 +733,13 @@ func (runtime *Runtime) Unmount(container *Container) error {
} }
func (runtime *Runtime) Changes(container *Container) ([]archive.Change, error) { func (runtime *Runtime) Changes(container *Container) ([]archive.Change, error) {
if changer, ok := runtime.driver.(graphdriver.Changer); ok { // FIXME: Remove Changes method from runtime
return changer.Changes(container.ID) return runtime.driver.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)
} }
func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) { func (runtime *Runtime) Diff(container *Container) (archive.Archive, error) {
if differ, ok := runtime.driver.(graphdriver.Differ); ok { // FIXME: Remove Diff method from runtime
return differ.Diff(container.ID) return runtime.driver.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)
} }
func linkLxcStart(root string) error { func linkLxcStart(root string) error {