Skip to content

Commit

Permalink
New 'dummy' driver uses plain directories and regular copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomon Hykes committed Nov 8, 2013
1 parent 0a9df6b commit 81674fb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions graphdriver/driver.go
Expand Up @@ -28,6 +28,7 @@ var (
priority = []string{
"aufs",
"devicemapper",
"dummy",
}
)

Expand Down
84 changes: 84 additions & 0 deletions 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 change: 1 addition & 0 deletions runtime.go
Expand Up @@ -10,6 +10,7 @@ import (
_ "github.com/dotcloud/docker/devmapper"
"github.com/dotcloud/docker/gograph"
"github.com/dotcloud/docker/graphdriver"
_ "github.com/dotcloud/docker/graphdriver/dummy"
"github.com/dotcloud/docker/utils"
"io"
"io/ioutil"
Expand Down

0 comments on commit 81674fb

Please sign in to comment.