зеркало из https://github.com/microsoft/docker.git
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:
Родитель
ec6fe9f200
Коммит
4d1a537433
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)")
|
||||
}
|
||||
|
|
45
runtime.go
45
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 {
|
||||
|
|
Загрузка…
Ссылка в новой задаче