From 1daf242c8bafa0447c099b0e49826667a8155c5c Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Tue, 8 Oct 2013 16:35:47 +0000 Subject: [PATCH] fix rm -v --- server.go | 3 +++ server_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/server.go b/server.go index 5bfbc96924..1255b83f36 100644 --- a/server.go +++ b/server.go @@ -16,6 +16,7 @@ import ( "os" "os/exec" "path" + "path/filepath" "runtime" "strings" "sync" @@ -958,6 +959,8 @@ func (srv *Server) ContainerDestroy(name string, removeVolume bool) error { volumes := make(map[string]struct{}) // Store all the deleted containers volumes for _, volumeId := range container.Volumes { + volumeId = strings.TrimRight(volumeId, "/layer") + volumeId = filepath.Base(volumeId) volumes[volumeId] = struct{}{} } if err := srv.runtime.Destroy(container); err != nil { diff --git a/server_test.go b/server_test.go index ad87b4d0a3..ee9549d7b7 100644 --- a/server_test.go +++ b/server_test.go @@ -108,6 +108,45 @@ func TestCreateRm(t *testing.T) { } +func TestCreateRmVolumes(t *testing.T) { + runtime := mkRuntime(t) + defer nuke(runtime) + + srv := &Server{runtime: runtime} + + config, hostConfig, _, err := ParseRun([]string{"-v", "/srv", GetTestImage(runtime).ID, "echo test"}, nil) + if err != nil { + t.Fatal(err) + } + + id, err := srv.ContainerCreate(config) + if err != nil { + t.Fatal(err) + } + + if len(runtime.List()) != 1 { + t.Errorf("Expected 1 container, %v found", len(runtime.List())) + } + + err = srv.ContainerStart(id, hostConfig) + if err != nil { + t.Fatal(err) + } + + err = srv.ContainerStop(id, 1) + if err != nil { + t.Fatal(err) + } + + if err = srv.ContainerDestroy(id, true); err != nil { + t.Fatal(err) + } + + if len(runtime.List()) != 0 { + t.Errorf("Expected 0 container, %v found", len(runtime.List())) + } +} + func TestCommit(t *testing.T) { runtime := mkRuntime(t) defer nuke(runtime)