mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make sure only links are removed and not names
This commit is contained in:
parent
a52e23c5e4
commit
7e8b2c3836
3 changed files with 34 additions and 13 deletions
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
30
server.go
30
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue