diff --git a/gograph/gograph.go b/gograph/gograph.go index ff0b854064..94ce90afb4 100644 --- a/gograph/gograph.go +++ b/gograph/gograph.go @@ -179,6 +179,9 @@ func (db *Database) get(name string) (*Entity, error) { parts := split(name) for i := 1; i < len(parts); i++ { p := parts[i] + if p == "" { + continue + } next := db.child(e, p) if next == nil { diff --git a/gograph/gograph_test.go b/gograph/gograph_test.go index 7107ef55ea..dba8ed1080 100644 --- a/gograph/gograph_test.go +++ b/gograph/gograph_test.go @@ -482,10 +482,22 @@ func TestExistsFalse(t *testing.T) { db, dbpath := newTestDb(t) defer destroyTestDb(dbpath) - db.Set("toerhe", "1") + db.Set("/toerhe", "1") if db.Exists("/testing") { t.Fatalf("/tesing should not exist") } } + +func TestGetNameWithTrailingSlash(t *testing.T) { + db, dbpath := newTestDb(t) + defer destroyTestDb(dbpath) + + db.Set("/todo", "1") + + e := db.Get("/todo/") + if e == nil { + t.Fatalf("Entity should not be nil") + } +} diff --git a/server.go b/server.go index 6cbb6db340..2cb6771178 100644 --- a/server.go +++ b/server.go @@ -990,20 +990,17 @@ func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool) parent, n := path.Split(name) pe := srv.runtime.containerGraph.Get(parent) - if pe != nil { - parentContainer := srv.runtime.Get(pe.ID()) - - if parentContainer != nil && parentContainer.activeLinks != nil { - if link, exists := parentContainer.activeLinks[n]; exists { - link.Disable() - } else { - utils.Debugf("Could not find active link for %s", name) - } - } + if pe == nil { + return fmt.Errorf("Cannot get parent %s for name %s", parent, name) } + parentContainer := srv.runtime.Get(pe.ID()) - if name[1:] == container.ID { - return fmt.Errorf("Conflict, cannot remove default link %s", name) + if parentContainer != nil && parentContainer.activeLinks != nil { + if link, exists := parentContainer.activeLinks[n]; exists { + link.Disable() + } else { + utils.Debugf("Could not find active link for %s", name) + } } if err := srv.runtime.containerGraph.Delete(name); err != nil { @@ -1011,6 +1008,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool) } return nil } + if container != nil { if container.State.Running { return fmt.Errorf("Impossible to remove a running container, please stop it first") @@ -1215,6 +1213,7 @@ func (srv *Server) RegisterLinks(name string, hostConfig *HostConfig) error { if container == nil { return fmt.Errorf("No such container: %s", name) } + // Register links if hostConfig != nil && hostConfig.Links != nil { for _, l := range hostConfig.Links { @@ -1234,6 +1233,13 @@ func (srv *Server) RegisterLinks(name string, hostConfig *HostConfig) error { return err } } + + // After we load all the links into the runtime + // set them to nil on the hostconfig + hostConfig.Links = nil + if err := container.SaveHostConfig(hostConfig); err != nil { + return err + } } return nil }