Skip to content

Commit 3110cf3

Browse files
committed
snapshot: rename layer manipulator to snapshot
Signed-off-by: Stephen J Day <stephen.day@docker.com>
1 parent afb175d commit 3110cf3

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

layers.go renamed to snapshot/manager.go

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package containerkit
1+
package snapshot
22

33
import (
44
"errors"
@@ -7,39 +7,41 @@ import (
77
"os"
88
"path/filepath"
99
"strings"
10+
11+
"github.com/docker/containerkit"
1012
)
1113

1214
var (
1315
errNotImplemented = errors.New("not implemented")
1416
)
1517

16-
// LayerManipulator provides an API for allocating, snapshotting and mounting
18+
// Manager provides an API for allocating, snapshotting and mounting
1719
// abstract, layer-based filesytems. The model works by building up sets of
1820
// directories with parent-child relationships.
1921
//
2022
// These differ from the concept of the graphdriver in that the
21-
// LayerManipulator has no knowledge of images or containers. Users simply
23+
// Manager has no knowledge of images or containers. Users simply
2224
// prepare and commit directories. We also avoid the integration between graph
2325
// driver's and the tar format used to represent the changesets.
2426
//
2527
// Importing a Layer
2628
//
27-
// To import a layer, we simply have the LayerManipulator provide a list of
29+
// To import a layer, we simply have the Manager provide a list of
2830
// mounts to be applied such that our dst will capture a changeset. We start
2931
// out by getting a path to the layer tar file and creating a temp location to
3032
// unpack it to:
3133
//
3234
// layerPath, tmpLocation := getLayerPath(), mkTmpDir() // just a path to layer tar file.
3335
//
34-
// We then use a LayerManipulator to prepare the temporary location as a
36+
// We then use a Manager to prepare the temporary location as a
3537
// snapshot point:
3638
//
37-
// lm := NewLayerManipulator()
39+
// lm := NewManager()
3840
// mounts, err := lm.Prepare(tmpLocation, "")
3941
// if err != nil { ... }
4042
//
4143
// Note that we provide "" as the parent, since we are applying the diff to an
42-
// empty directory. We get back a list of mounts from LayerManipulator.Prepare.
44+
// empty directory. We get back a list of mounts from Manager.Prepare.
4345
// Before proceeding, we perform all these mounts:
4446
//
4547
// if err := MountAll(mounts); err != nil { ... }
@@ -67,35 +69,35 @@ var (
6769
// diffPath := filepath.Join("/layers", digest) // name location for the uncompressed layer digest
6870
// if err := lm.Commit(diffPath, tmpLocation); err != nil { ... }
6971
//
70-
// Now, we have a layer in the LayerManipulator that can be accessed with the
72+
// Now, we have a layer in the Manager that can be accessed with the
7173
// opaque diffPath provided during commit.
7274
//
7375
// Importing the Next Layer
7476
//
7577
// Making a layer depend on the above is identical to the process described
7678
// above except that the parent is provided as diffPath when calling
77-
// LayerManipulator.Prepare:
79+
// Manager.Prepare:
7880
//
7981
// mounts, err := lm.Prepare(tmpLocation, parentDiffPath)
8082
//
8183
// The diff will be captured at tmpLocation, as the layer is applied.
8284
//
8385
// Running a Container
8486
//
85-
// To run a container, we simply provide LayerManipulator.Prepare the diffPath
87+
// To run a container, we simply provide Manager.Prepare the diffPath
8688
// of the image we want to start the container from. After mounting, the
8789
// prepared path can be used directly as the container's filesystem:
8890
//
8991
// mounts, err := lm.Prepare(containerRootFS, imageDiffPath)
9092
//
9193
// The returned mounts can then be passed directly to the container runtime. If
9294
// one would like to create a new image from the filesystem,
93-
// LayerManipulator.Commit is called:
95+
// Manager.Commit is called:
9496
//
9597
// if err := lm.Commit(newImageDiff, containerRootFS); err != nil { ... }
9698
//
97-
// Alternatively, for most container runs, LayerManipulator.Rollback will be
98-
// called to signal LayerManipulator to abandon the changes.
99+
// Alternatively, for most container runs, Manager.Rollback will be
100+
// called to signal Manager to abandon the changes.
99101
//
100102
// TODO(stevvooe): Consider an alternate API that provides an active object to
101103
// represent the lifecycle:
@@ -104,9 +106,9 @@ var (
104106
// mountAll(work.Mounts())
105107
// work.Commit() || work.Rollback()
106108
//
107-
// TODO(stevvooe): LayerManipulator should be an interface with several
109+
// TODO(stevvooe): Manager should be an interface with several
108110
// implementations, similar to graphdriver.
109-
type LayerManipulator struct {
111+
type Manager struct {
110112
root string // root provides paths for internal storage.
111113

112114
// just a simple overlay implementation.
@@ -120,12 +122,12 @@ type activeLayer struct {
120122
workdir string
121123
}
122124

123-
func NewLayerManipulator(root string) (*LayerManipulator, error) {
125+
func NewManager(root string) (*Manager, error) {
124126
if err := os.MkdirAll(root, 0777); err != nil {
125127
return nil, err
126128
}
127129

128-
return &LayerManipulator{
130+
return &Manager{
129131
root: root,
130132
active: make(map[string]activeLayer),
131133
parents: make(map[string]string),
@@ -142,9 +144,9 @@ func NewLayerManipulator(root string) (*LayerManipulator, error) {
142144
// working directory for any associated activity, such as running a container
143145
// or importing a layer.
144146
//
145-
// Once the writes have completed, LayerManipulator.Commit or
146-
// LayerManipulator.Rollback should be called on dst.
147-
func (lm *LayerManipulator) Prepare(dst, parent string) ([]Mount, error) {
147+
// Once the writes have completed, Manager.Commit or
148+
// Manager.Rollback should be called on dst.
149+
func (lm *Manager) Prepare(dst, parent string) ([]containerkit.Mount, error) {
148150
// we want to build up lowerdir, upperdir and workdir options for the
149151
// overlay mount.
150152
//
@@ -208,7 +210,7 @@ func (lm *LayerManipulator) Prepare(dst, parent string) ([]Mount, error) {
208210
//
209211
// The contents of diff are opaque to the caller and may be specific to the
210212
// implementation of the layer backend.
211-
func (lm *LayerManipulator) Commit(diff, dst string) error {
213+
func (lm *Manager) Commit(diff, dst string) error {
212214
active, ok := lm.active[dst]
213215
if !ok {
214216
return fmt.Errorf("%q must be an active layer", dst)
@@ -234,7 +236,7 @@ func (lm *LayerManipulator) Commit(diff, dst string) error {
234236

235237
// Rollback can be called after prepare if the caller would like to abandon the
236238
// changeset.
237-
func (lm *LayerManipulator) Rollback(dst string) error {
239+
func (lm *Manager) Rollback(dst string) error {
238240
active, ok := lm.active[dst]
239241
if !ok {
240242
return fmt.Errorf("%q must be an active layer", dst)
@@ -249,7 +251,7 @@ func (lm *LayerManipulator) Rollback(dst string) error {
249251
}
250252

251253
// Parent returns the parent of the layer at diff.
252-
func (lm *LayerManipulator) Parent(diff string) string {
254+
func (lm *Manager) Parent(diff string) string {
253255
return lm.parents[diff]
254256
}
255257

@@ -289,6 +291,6 @@ type Change struct {
289291
// see this patten used in several tar'ing methods in pkg/archive.
290292

291293
// Changes returns the list of changes from the diff's parent.
292-
func (lm *LayerManipulator) Changes(diff string) ([]Change, error) {
294+
func (lm *Manager) Changes(diff string) ([]Change, error) {
293295
return nil, errNotImplemented
294296
}

layers_test.go renamed to snapshot/manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package containerkit
1+
package snapshot
22

33
import (
44
"io/ioutil"
@@ -8,10 +8,10 @@ import (
88
"testing"
99
)
1010

11-
// TestLayerManipulatorBasic implements something similar to the conceptual
11+
// TestSnapshotManagerBasic implements something similar to the conceptual
1212
// examples we've discussed thus far. It does perform mounts, so you must run
1313
// as root.
14-
func TestLayerManipulatorBasic(t *testing.T) {
14+
func TestSnapshotManagerBasic(t *testing.T) {
1515
tmpDir, err := ioutil.TempDir("", "test-layman-")
1616
if err != nil {
1717
t.Fatal(err)
@@ -20,7 +20,7 @@ func TestLayerManipulatorBasic(t *testing.T) {
2020

2121
root := filepath.Join(tmpDir, "root")
2222

23-
lm, err := NewLayerManipulator(root)
23+
lm, err := NewManager(root)
2424
if err != nil {
2525
t.Fatal(err)
2626
}

0 commit comments

Comments
 (0)