|
@@ -10,13 +10,13 @@ import (
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
-// A Graph is a store for versioned filesystem images, and the relationship between them.
|
|
|
|
|
|
+// A Graph is a store for versioned filesystem images and the relationship between them.
|
|
type Graph struct {
|
|
type Graph struct {
|
|
Root string
|
|
Root string
|
|
idIndex *TruncIndex
|
|
idIndex *TruncIndex
|
|
}
|
|
}
|
|
|
|
|
|
-// NewGraph instanciates a new graph at the given root path in the filesystem.
|
|
|
|
|
|
+// NewGraph instantiates a new graph at the given root path in the filesystem.
|
|
// `root` will be created if it doesn't exist.
|
|
// `root` will be created if it doesn't exist.
|
|
func NewGraph(root string) (*Graph, error) {
|
|
func NewGraph(root string) (*Graph, error) {
|
|
abspath, err := filepath.Abs(root)
|
|
abspath, err := filepath.Abs(root)
|
|
@@ -140,14 +140,14 @@ func (graph *Graph) Mktemp(id string) (string, error) {
|
|
}
|
|
}
|
|
|
|
|
|
// Garbage returns the "garbage", a staging area for deleted images.
|
|
// Garbage returns the "garbage", a staging area for deleted images.
|
|
-// This allows images ot be deleted atomically by os.Rename(), instead of
|
|
|
|
-// os.RemoveAll() which is prone to race conditions
|
|
|
|
|
|
+// This allows images to be deleted atomically by os.Rename(), instead of
|
|
|
|
+// os.RemoveAll() which is prone to race conditions.
|
|
func (graph *Graph) Garbage() (*Graph, error) {
|
|
func (graph *Graph) Garbage() (*Graph, error) {
|
|
return NewGraph(path.Join(graph.Root, ":garbage:"))
|
|
return NewGraph(path.Join(graph.Root, ":garbage:"))
|
|
}
|
|
}
|
|
|
|
|
|
-// Check if given error is "not empty"
|
|
|
|
-// Note: this is the way golang do it internally with os.IsNotExists
|
|
|
|
|
|
+// Check if given error is "not empty".
|
|
|
|
+// Note: this is the way golang does it internally with os.IsNotExists.
|
|
func isNotEmpty(err error) bool {
|
|
func isNotEmpty(err error) bool {
|
|
switch pe := err.(type) {
|
|
switch pe := err.(type) {
|
|
case nil:
|
|
case nil:
|
|
@@ -190,7 +190,7 @@ func (graph *Graph) Delete(id string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// Undelete moves an image back from the garbage to the main graph
|
|
|
|
|
|
+// Undelete moves an image back from the garbage to the main graph.
|
|
func (graph *Graph) Undelete(id string) error {
|
|
func (graph *Graph) Undelete(id string) error {
|
|
garbage, err := graph.Garbage()
|
|
garbage, err := graph.Garbage()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -203,7 +203,7 @@ func (graph *Graph) Undelete(id string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-// GarbageCollect definitely deletes all images moved to the garbage
|
|
|
|
|
|
+// GarbageCollect definitely deletes all images moved to the garbage.
|
|
func (graph *Graph) GarbageCollect() error {
|
|
func (graph *Graph) GarbageCollect() error {
|
|
garbage, err := graph.Garbage()
|
|
garbage, err := graph.Garbage()
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -212,7 +212,7 @@ func (graph *Graph) GarbageCollect() error {
|
|
return os.RemoveAll(garbage.Root)
|
|
return os.RemoveAll(garbage.Root)
|
|
}
|
|
}
|
|
|
|
|
|
-// Map returns a list of all images in the graph, addressable by ID
|
|
|
|
|
|
+// Map returns a list of all images in the graph, addressable by ID.
|
|
func (graph *Graph) Map() (map[string]*Image, error) {
|
|
func (graph *Graph) Map() (map[string]*Image, error) {
|
|
// FIXME: this should replace All()
|
|
// FIXME: this should replace All()
|
|
all, err := graph.All()
|
|
all, err := graph.All()
|
|
@@ -226,7 +226,7 @@ func (graph *Graph) Map() (map[string]*Image, error) {
|
|
return images, nil
|
|
return images, nil
|
|
}
|
|
}
|
|
|
|
|
|
-// All returns a list of all images in the graph
|
|
|
|
|
|
+// All returns a list of all images in the graph.
|
|
func (graph *Graph) All() ([]*Image, error) {
|
|
func (graph *Graph) All() ([]*Image, error) {
|
|
var images []*Image
|
|
var images []*Image
|
|
err := graph.WalkAll(func(image *Image) {
|
|
err := graph.WalkAll(func(image *Image) {
|