Skip to content

Commit

Permalink
Folded graph/ back into main package
Browse files Browse the repository at this point in the history
  • Loading branch information
Solomon Hykes committed Mar 22, 2013
1 parent 44faa07 commit ef71196
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion graph/archive.go → archive.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion graph/archive_test.go → archive_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"io/ioutil"
Expand Down
2 changes: 1 addition & 1 deletion graph/changes.go → changes.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ func NewServer() (*Server, error) {
// if err != nil {
// return nil, err
// }
runtime, err := New()
runtime, err := NewRuntime()
if err != nil {
return nil, err
}
Expand Down
22 changes: 8 additions & 14 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/dotcloud/docker/graph"
"github.com/kr/pty"
"io"
"io/ioutil"
Expand Down Expand Up @@ -63,11 +62,6 @@ type NetworkSettings struct {
PortMapping map[string]string
}

func GenerateId() string {
return graph.GenerateId() // Re-use the same code to generate container and image IDs
// (this might change when image Ids become content-based)
}

func (container *Container) Cmd() *exec.Cmd {
return container.cmd
}
Expand Down Expand Up @@ -376,15 +370,15 @@ func (container *Container) Wait() int {
return container.State.ExitCode
}

func (container *Container) ExportRw() (graph.Archive, error) {
return graph.Tar(container.rwPath(), graph.Uncompressed)
func (container *Container) ExportRw() (Archive, error) {
return Tar(container.rwPath(), Uncompressed)
}

func (container *Container) Export() (graph.Archive, error) {
func (container *Container) Export() (Archive, error) {
if err := container.EnsureMounted(); err != nil {
return nil, err
}
return graph.Tar(container.RootfsPath(), graph.Uncompressed)
return Tar(container.RootfsPath(), Uncompressed)
}

func (container *Container) WaitTimeout(timeout time.Duration) error {
Expand Down Expand Up @@ -420,27 +414,27 @@ func (container *Container) Mount() error {
return image.Mount(container.RootfsPath(), container.rwPath())
}

func (container *Container) Changes() ([]graph.Change, error) {
func (container *Container) Changes() ([]Change, error) {
image, err := container.GetImage()
if err != nil {
return nil, err
}
return image.Changes(container.rwPath())
}

func (container *Container) GetImage() (*graph.Image, error) {
func (container *Container) GetImage() (*Image, error) {
if container.runtime == nil {
return nil, fmt.Errorf("Can't get image of unregistered container")
}
return container.runtime.graph.Get(container.Image)
}

func (container *Container) Mounted() (bool, error) {
return graph.Mounted(container.RootfsPath())
return Mounted(container.RootfsPath())
}

func (container *Container) Unmount() error {
return graph.Unmount(container.RootfsPath())
return Unmount(container.RootfsPath())
}

func (container *Container) logPath(name string) string {
Expand Down
8 changes: 4 additions & 4 deletions graph/graph.go → graph.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"fmt"
Expand All @@ -13,7 +13,7 @@ type Graph struct {
Root string
}

func New(root string) (*Graph, error) {
func NewGraph(root string) (*Graph, error) {
abspath, err := filepath.Abs(root)
if err != nil {
return nil, err
Expand Down Expand Up @@ -84,7 +84,7 @@ func (graph *Graph) Register(layerData Archive, img *Image) error {
}

func (graph *Graph) Mktemp(id string) (string, error) {
tmp, err := New(path.Join(graph.Root, ":tmp:"))
tmp, err := NewGraph(path.Join(graph.Root, ":tmp:"))
if err != nil {
return "", fmt.Errorf("Couldn't create temp: %s", err)
}
Expand All @@ -95,7 +95,7 @@ func (graph *Graph) Mktemp(id string) (string, error) {
}

func (graph *Graph) Garbage() (*Graph, error) {
return New(path.Join(graph.Root, ":garbage:"))
return NewGraph(path.Join(graph.Root, ":garbage:"))
}

func (graph *Graph) Delete(id string) error {
Expand Down
6 changes: 3 additions & 3 deletions graph/graph_test.go → graph_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"archive/tar"
Expand Down Expand Up @@ -28,7 +28,7 @@ func TestInit(t *testing.T) {

// FIXME: Do more extensive tests (ex: create multiple, delete, recreate;
// create multiple, check the amount of images and paths, etc..)
func TestCreate(t *testing.T) {
func TestGraphCreate(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
archive, err := fakeTar()
Expand Down Expand Up @@ -177,7 +177,7 @@ func tempGraph(t *testing.T) *Graph {
if err != nil {
t.Fatal(err)
}
graph, err := New(tmp)
graph, err := NewGraph(tmp)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion graph/image.go → image.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion graph/mount.go → mount.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion graph/mount_darwin.go → mount_darwin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import "errors"

Expand Down
2 changes: 1 addition & 1 deletion graph/mount_linux.go → mount_linux.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import "syscall"

Expand Down
15 changes: 7 additions & 8 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package docker
import (
"container/list"
"fmt"
"github.com/dotcloud/docker/graph"
"io"
"io/ioutil"
"log"
Expand All @@ -19,8 +18,8 @@ type Runtime struct {
repository string
containers *list.List
networkManager *NetworkManager
graph *graph.Graph
repositories *graph.TagStore
graph *Graph
repositories *TagStore
}

var sysInitPath string
Expand Down Expand Up @@ -191,22 +190,22 @@ func (runtime *Runtime) restore() error {
return nil
}

func New() (*Runtime, error) {
return NewFromDirectory("/var/lib/docker")
func NewRuntime() (*Runtime, error) {
return NewRuntimeFromDirectory("/var/lib/docker")
}

func NewFromDirectory(root string) (*Runtime, error) {
func NewRuntimeFromDirectory(root string) (*Runtime, error) {
runtime_repo := path.Join(root, "containers")

if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
return nil, err
}

g, err := graph.New(path.Join(root, "graph"))
g, err := NewGraph(path.Join(root, "graph"))
if err != nil {
return nil, err
}
repositories, err := graph.NewTagStore(path.Join(root, "repositories"), g)
repositories, err := NewTagStore(path.Join(root, "repositories"), g)
if err != nil {
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
}
Expand Down
13 changes: 6 additions & 7 deletions runtime_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package docker

import (
"github.com/dotcloud/docker/graph"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -57,7 +56,7 @@ func init() {
unitTestStoreBase = root

// Make it our Store root
runtime, err := NewFromDirectory(root)
runtime, err := NewRuntimeFromDirectory(root)
if err != nil {
panic(err)
}
Expand All @@ -84,15 +83,15 @@ func newTestRuntime() (*Runtime, error) {
return nil, err
}

runtime, err := NewFromDirectory(root)
runtime, err := NewRuntimeFromDirectory(root)
if err != nil {
return nil, err
}

return runtime, nil
}

func GetTestImage(runtime *Runtime) *graph.Image {
func GetTestImage(runtime *Runtime) *Image {
imgs, err := runtime.graph.All()
if err != nil {
panic(err)
Expand All @@ -102,7 +101,7 @@ func GetTestImage(runtime *Runtime) *graph.Image {
return imgs[0]
}

func TestCreate(t *testing.T) {
func TestRuntimeCreate(t *testing.T) {
runtime, err := newTestRuntime()
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -269,7 +268,7 @@ func TestRestore(t *testing.T) {
t.Fatal(err)
}

runtime1, err := NewFromDirectory(root)
runtime1, err := NewRuntimeFromDirectory(root)
if err != nil {
t.Fatal(err)
}
Expand All @@ -294,7 +293,7 @@ func TestRestore(t *testing.T) {

// Here are are simulating a docker restart - that is, reloading all containers
// from scratch
runtime2, err := NewFromDirectory(root)
runtime2, err := NewRuntimeFromDirectory(root)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion graph/tags.go → tags.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package graph
package docker

import (
"encoding/json"
Expand Down

0 comments on commit ef71196

Please sign in to comment.