瀏覽代碼

New 'dummy' driver uses plain directories and regular copy

Solomon Hykes 11 年之前
父節點
當前提交
81674fbbdf
共有 3 個文件被更改,包括 86 次插入0 次删除
  1. 1 0
      graphdriver/driver.go
  2. 84 0
      graphdriver/dummy/driver.go
  3. 1 0
      runtime.go

+ 1 - 0
graphdriver/driver.go

@@ -28,6 +28,7 @@ var (
 	priority = []string{
 	priority = []string{
 		"aufs",
 		"aufs",
 		"devicemapper",
 		"devicemapper",
+		"dummy",
 	}
 	}
 )
 )
 
 

+ 84 - 0
graphdriver/dummy/driver.go

@@ -0,0 +1,84 @@
+package dummy
+
+import (
+	"github.com/dotcloud/docker/archive"
+	"github.com/dotcloud/docker/graphdriver"
+	"os"
+	"path"
+	"fmt"
+)
+
+func init() {
+	graphdriver.Register("dummy", Init)
+}
+
+func Init(home string) (graphdriver.Driver, error) {
+	d := &Driver{
+		home:      home,
+	}
+	return d, nil
+}
+
+type Driver struct {
+	home string
+}
+
+func (d *Driver) Cleanup() error {
+	return nil
+}
+
+func (d *Driver) Create(id string, parent string) error {
+	dir := d.dir(id)
+	if err := os.MkdirAll(path.Dir(dir), 0700); err != nil {
+		return err
+	}
+	if err := os.Mkdir(dir, 0700); err != nil {
+		return err
+	}
+	if parent == "" {
+		return nil
+	}
+	parentDir, err := d.Get(parent)
+	if err != nil {
+		return fmt.Errorf("%s: %s", parent, err)
+	}
+	if err := archive.CopyWithTar(parentDir, dir); err != nil {
+		return err
+	}
+	return nil
+}
+
+func (d *Driver) dir(id string) string {
+	return path.Join(d.home, "dir", path.Base(id))
+}
+
+
+func (d *Driver) Remove(id string) error {
+	if _, err := os.Stat(d.dir(id)); err != nil {
+		return err
+	}
+	return os.RemoveAll(d.dir(id))
+}
+
+func (d *Driver) Get(id string) (string, error) {
+	dir := d.dir(id)
+	if st, err := os.Stat(dir); err != nil {
+		return "", err
+	} else if !st.IsDir() {
+		return "", fmt.Errorf("%s: not a directory", dir)
+	}
+	return dir, nil
+}
+
+func (d *Driver) Diff(id string) (archive.Archive, error) {
+	return nil, fmt.Errorf("Not implemented")
+}
+
+func (d *Driver) DiffSize(id string) (int64, error) {
+	return -1, fmt.Errorf("Not implemented")
+}
+
+func (d *Driver) Changes(id string) ([]archive.Change, error) {
+	return nil, fmt.Errorf("Not implemented")
+}
+

+ 1 - 0
runtime.go

@@ -10,6 +10,7 @@ import (
 	_ "github.com/dotcloud/docker/devmapper"
 	_ "github.com/dotcloud/docker/devmapper"
 	"github.com/dotcloud/docker/gograph"
 	"github.com/dotcloud/docker/gograph"
 	"github.com/dotcloud/docker/graphdriver"
 	"github.com/dotcloud/docker/graphdriver"
+	_ "github.com/dotcloud/docker/graphdriver/dummy"
 	"github.com/dotcloud/docker/utils"
 	"github.com/dotcloud/docker/utils"
 	"io"
 	"io"
 	"io/ioutil"
 	"io/ioutil"