diff --git a/snapshot/btrfs.go b/snapshot/btrfs/btrfs.go similarity index 93% rename from snapshot/btrfs.go rename to snapshot/btrfs/btrfs.go index 32a40ff..f5ebd0e 100644 --- a/snapshot/btrfs.go +++ b/snapshot/btrfs/btrfs.go @@ -1,6 +1,7 @@ -package snapshot +package btrfs import ( + "crypto/sha256" "fmt" "os" "path/filepath" @@ -26,7 +27,6 @@ func (lm *Btrfs) Prepare(key, parent string) ([]containerd.Mount, error) { dir := filepath.Join(active, hash(key)) - fmt.Println("dir", dir) if parent == "" { // create new subvolume // btrfs subvolume create /dir @@ -69,3 +69,7 @@ func (lm *Btrfs) Commit(name, key string) error { return btrfs.SubvolDelete(dir) } + +func hash(k string) string { + return fmt.Sprintf("%x", sha256.Sum224([]byte(k))) +} diff --git a/snapshot/btrfs_test.go b/snapshot/btrfs/btrfs_test.go similarity index 96% rename from snapshot/btrfs_test.go rename to snapshot/btrfs/btrfs_test.go index 7fa3a68..5678bce 100644 --- a/snapshot/btrfs_test.go +++ b/snapshot/btrfs/btrfs_test.go @@ -1,4 +1,4 @@ -package snapshot +package btrfs import ( "bytes" @@ -10,6 +10,7 @@ import ( "testing" "github.com/docker/containerd" + "github.com/docker/containerd/snapshot/testutil" btrfs "github.com/stevvooe/go-btrfs" ) @@ -53,7 +54,7 @@ func TestBtrfs(t *testing.T) { if err := containerd.MountAll(mounts...); err != nil { t.Fatal(err) } - defer unmountAll(t, mounts) + defer testutil.UnmountAll(t, mounts) // write in some data if err := ioutil.WriteFile(filepath.Join(mounts[0].Target, "foo"), []byte("content"), 0777); err != nil { @@ -89,7 +90,7 @@ func TestBtrfs(t *testing.T) { if err := containerd.MountAll(mounts...); err != nil { t.Fatal(err) } - defer unmountAll(t, mounts) + defer testutil.UnmountAll(t, mounts) // TODO(stevvooe): Verify contents of "foo" if err := ioutil.WriteFile(filepath.Join(mounts[0].Target, "bar"), []byte("content"), 0777); err != nil { @@ -182,7 +183,7 @@ func setupBtrfsLoopbackDevice(t *testing.T) *testDevice { // file holding the disk image. func removeBtrfsLoopbackDevice(t *testing.T, device *testDevice) { // unmount - unmount(t, device.mountPoint) + testutil.Unmount(t, device.mountPoint) // detach device t.Log("Removing loop device") diff --git a/snapshot/manager_test.go b/snapshot/manager_test.go index 992b65e..5b21434 100644 --- a/snapshot/manager_test.go +++ b/snapshot/manager_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/docker/containerd" + "github.com/docker/containerd/snapshot/testutil" ) // TestSnapshotManagerBasic implements something similar to the conceptual @@ -58,7 +59,7 @@ func TestSnapshotManagerBasic(t *testing.T) { if err := containerd.MountAll(mounts...); err != nil { t.Fatal(err) } - defer unmountAll(t, mounts) + defer testutil.UnmountAll(t, mounts) if err := ioutil.WriteFile(filepath.Join(preparing, "foo"), []byte("foo\n"), 0777); err != nil { t.Fatal(err) @@ -88,7 +89,7 @@ func TestSnapshotManagerBasic(t *testing.T) { if err := containerd.MountAll(mounts...); err != nil { t.Fatal(err) } - defer unmountAll(t, mounts) + defer testutil.UnmountAll(t, mounts) for _, mount := range mounts { if !strings.HasPrefix(mount.Target, next) { diff --git a/snapshot/naive.go b/snapshot/naive/naive.go similarity index 99% rename from snapshot/naive.go rename to snapshot/naive/naive.go index 449afd8..5f50162 100644 --- a/snapshot/naive.go +++ b/snapshot/naive/naive.go @@ -1,4 +1,4 @@ -package snapshot +package naive import ( "fmt" diff --git a/snapshot/naive_test.go b/snapshot/naive/naive_test.go similarity index 99% rename from snapshot/naive_test.go rename to snapshot/naive/naive_test.go index 8ab5f88..0d72997 100644 --- a/snapshot/naive_test.go +++ b/snapshot/naive/naive_test.go @@ -1,4 +1,4 @@ -package snapshot +package naive import ( "io/ioutil" diff --git a/snapshot/overlayfs.go b/snapshot/overlay/overlayfs.go similarity index 99% rename from snapshot/overlayfs.go rename to snapshot/overlay/overlayfs.go index e82b573..a3f5f0e 100644 --- a/snapshot/overlayfs.go +++ b/snapshot/overlay/overlayfs.go @@ -1,4 +1,4 @@ -package snapshot +package overlay import ( "crypto/md5" diff --git a/snapshot/overlayfs_test.go b/snapshot/overlay/overlayfs_test.go similarity index 99% rename from snapshot/overlayfs_test.go rename to snapshot/overlay/overlayfs_test.go index ebc4aa4..0b67131 100644 --- a/snapshot/overlayfs_test.go +++ b/snapshot/overlay/overlayfs_test.go @@ -1,4 +1,4 @@ -package snapshot +package overlay import ( "io/ioutil" diff --git a/snapshot/common_test.go b/snapshot/testutil/helpers.go similarity index 64% rename from snapshot/common_test.go rename to snapshot/testutil/helpers.go index 27e0d9a..9ae954b 100644 --- a/snapshot/common_test.go +++ b/snapshot/testutil/helpers.go @@ -1,4 +1,4 @@ -package snapshot +package testutil import ( "os/exec" @@ -7,13 +7,13 @@ import ( "github.com/docker/containerd" ) -func unmountAll(t *testing.T, mounts []containerd.Mount) { +func UnmountAll(t *testing.T, mounts []containerd.Mount) { for _, mount := range mounts { - unmount(t, mount.Target) + Unmount(t, mount.Target) } } -func unmount(t *testing.T, mountPoint string) { +func Unmount(t *testing.T, mountPoint string) { t.Log("unmount", mountPoint) umount := exec.Command("umount", mountPoint) err := umount.Run()