зеркало из https://github.com/microsoft/docker.git
Make sure only links are removed and not names
This commit is contained in:
Родитель
a52e23c5e4
Коммит
7e8b2c3836
|
@ -179,6 +179,9 @@ func (db *Database) get(name string) (*Entity, error) {
|
||||||
parts := split(name)
|
parts := split(name)
|
||||||
for i := 1; i < len(parts); i++ {
|
for i := 1; i < len(parts); i++ {
|
||||||
p := parts[i]
|
p := parts[i]
|
||||||
|
if p == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
next := db.child(e, p)
|
next := db.child(e, p)
|
||||||
if next == nil {
|
if next == nil {
|
||||||
|
|
|
@ -482,10 +482,22 @@ func TestExistsFalse(t *testing.T) {
|
||||||
db, dbpath := newTestDb(t)
|
db, dbpath := newTestDb(t)
|
||||||
defer destroyTestDb(dbpath)
|
defer destroyTestDb(dbpath)
|
||||||
|
|
||||||
db.Set("toerhe", "1")
|
db.Set("/toerhe", "1")
|
||||||
|
|
||||||
if db.Exists("/testing") {
|
if db.Exists("/testing") {
|
||||||
t.Fatalf("/tesing should not exist")
|
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)
|
parent, n := path.Split(name)
|
||||||
|
|
||||||
pe := srv.runtime.containerGraph.Get(parent)
|
pe := srv.runtime.containerGraph.Get(parent)
|
||||||
if pe != nil {
|
if pe == nil {
|
||||||
parentContainer := srv.runtime.Get(pe.ID())
|
return fmt.Errorf("Cannot get parent %s for name %s", parent, 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
parentContainer := srv.runtime.Get(pe.ID())
|
||||||
|
|
||||||
if name[1:] == container.ID {
|
if parentContainer != nil && parentContainer.activeLinks != nil {
|
||||||
return fmt.Errorf("Conflict, cannot remove default link %s", name)
|
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 {
|
if err := srv.runtime.containerGraph.Delete(name); err != nil {
|
||||||
|
@ -1011,6 +1008,7 @@ func (srv *Server) ContainerDestroy(name string, removeVolume, removeLink bool)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if container != nil {
|
if container != nil {
|
||||||
if container.State.Running {
|
if container.State.Running {
|
||||||
return fmt.Errorf("Impossible to remove a running container, please stop it first")
|
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 {
|
if container == nil {
|
||||||
return fmt.Errorf("No such container: %s", name)
|
return fmt.Errorf("No such container: %s", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register links
|
// Register links
|
||||||
if hostConfig != nil && hostConfig.Links != nil {
|
if hostConfig != nil && hostConfig.Links != nil {
|
||||||
for _, l := range hostConfig.Links {
|
for _, l := range hostConfig.Links {
|
||||||
|
@ -1234,6 +1233,13 @@ func (srv *Server) RegisterLinks(name string, hostConfig *HostConfig) error {
|
||||||
return err
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче