snapshot: Add context to Snapshotter interface
Signed-off-by: Samuel Karp <skarp@amazon.com>
This commit is contained in:
parent
d377454659
commit
4382d553ea
6 changed files with 60 additions and 47 deletions
|
@ -1,6 +1,7 @@
|
|||
package overlay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -43,7 +44,7 @@ func NewSnapshotter(root string) (*Snapshotter, error) {
|
|||
//
|
||||
// Should be used for parent resolution, existence checks and to discern
|
||||
// the kind of snapshot.
|
||||
func (o *Snapshotter) Stat(key string) (snapshot.Info, error) {
|
||||
func (o *Snapshotter) Stat(ctx context.Context, key string) (snapshot.Info, error) {
|
||||
path, err := o.links.get(filepath.Join(o.root, "index", hash(key)))
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
|
@ -100,7 +101,7 @@ func (o *Snapshotter) stat(path string) (snapshot.Info, error) {
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (o *Snapshotter) Prepare(key, parent string) ([]containerd.Mount, error) {
|
||||
func (o *Snapshotter) Prepare(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
|
||||
active, err := o.newActiveDir(key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -113,7 +114,7 @@ func (o *Snapshotter) Prepare(key, parent string) ([]containerd.Mount, error) {
|
|||
return active.mounts(o.links)
|
||||
}
|
||||
|
||||
func (o *Snapshotter) View(key, parent string) ([]containerd.Mount, error) {
|
||||
func (o *Snapshotter) View(ctx context.Context, key, parent string) ([]containerd.Mount, error) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
|
@ -121,24 +122,24 @@ func (o *Snapshotter) View(key, parent string) ([]containerd.Mount, error) {
|
|||
// called on an read-write or readonly transaction.
|
||||
//
|
||||
// This can be used to recover mounts after calling View or Prepare.
|
||||
func (o *Snapshotter) Mounts(key string) ([]containerd.Mount, error) {
|
||||
func (o *Snapshotter) Mounts(ctx context.Context, key string) ([]containerd.Mount, error) {
|
||||
active := o.getActive(key)
|
||||
return active.mounts(o.links)
|
||||
}
|
||||
|
||||
func (o *Snapshotter) Commit(name, key string) error {
|
||||
func (o *Snapshotter) Commit(ctx context.Context, name, key string) error {
|
||||
active := o.getActive(key)
|
||||
return active.commit(name, o.links)
|
||||
}
|
||||
|
||||
// Remove abandons the transaction identified by key. All resources
|
||||
// associated with the key will be removed.
|
||||
func (o *Snapshotter) Remove(key string) error {
|
||||
func (o *Snapshotter) Remove(ctx context.Context, key string) error {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
// Walk the committed snapshots.
|
||||
func (o *Snapshotter) Walk(fn func(snapshot.Info) error) error {
|
||||
func (o *Snapshotter) Walk(ctx context.Context, fn func(context.Context, snapshot.Info) error) error {
|
||||
root := filepath.Join(o.root, "index")
|
||||
return filepath.Walk(root, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
|
@ -166,7 +167,7 @@ func (o *Snapshotter) Walk(fn func(snapshot.Info) error) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := fn(si); err != nil {
|
||||
if err := fn(ctx, si); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package overlay
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -25,6 +26,7 @@ func TestOverlay(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOverlayMounts(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -35,7 +37,7 @@ func TestOverlayMounts(t *testing.T) {
|
|||
t.Error(err)
|
||||
return
|
||||
}
|
||||
mounts, err := o.Prepare("/tmp/test", "")
|
||||
mounts, err := o.Prepare(ctx, "/tmp/test", "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -60,6 +62,7 @@ func TestOverlayMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestOverlayCommit(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -71,7 +74,7 @@ func TestOverlayCommit(t *testing.T) {
|
|||
return
|
||||
}
|
||||
key := "/tmp/test"
|
||||
mounts, err := o.Prepare(key, "")
|
||||
mounts, err := o.Prepare(ctx, key, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -81,13 +84,14 @@ func TestOverlayCommit(t *testing.T) {
|
|||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := o.Commit("base", key); err != nil {
|
||||
if err := o.Commit(ctx, "base", key); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverlayOverlayMount(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -99,16 +103,16 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
return
|
||||
}
|
||||
key := "/tmp/test"
|
||||
mounts, err := o.Prepare(key, "")
|
||||
mounts, err := o.Prepare(ctx, key, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := o.Commit("base", key); err != nil {
|
||||
if err := o.Commit(ctx, "base", key); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if mounts, err = o.Prepare("/tmp/layer2", "base"); err != nil {
|
||||
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
@ -142,6 +146,7 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
|
||||
func TestOverlayOverlayRead(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
ctx := context.TODO()
|
||||
root, err := ioutil.TempDir("", "overlay")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
@ -153,7 +158,7 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||
return
|
||||
}
|
||||
key := "/tmp/test"
|
||||
mounts, err := o.Prepare(key, "")
|
||||
mounts, err := o.Prepare(ctx, key, "")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -163,11 +168,11 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if err := o.Commit("base", key); err != nil {
|
||||
if err := o.Commit(ctx, "base", key); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
if mounts, err = o.Prepare("/tmp/layer2", "base"); err != nil {
|
||||
if mounts, err = o.Prepare(ctx, "/tmp/layer2", "base"); err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue